-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageServiceController.g.cs
More file actions
162 lines (147 loc) · 6.45 KB
/
ImageServiceController.g.cs
File metadata and controls
162 lines (147 loc) · 6.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using IntelliTect.Coalesce;
using IntelliTect.Coalesce.Api;
using IntelliTect.Coalesce.Api.Behaviors;
using IntelliTect.Coalesce.Api.Controllers;
using IntelliTect.Coalesce.Api.DataSources;
using IntelliTect.Coalesce.Mapping;
using IntelliTect.Coalesce.Mapping.IncludeTrees;
using IntelliTect.Coalesce.Models;
using IntelliTect.Coalesce.TypeDefinition;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SyncUp.Web.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace SyncUp.Web.Api
{
[Route("api/ImageService")]
[ServiceFilter(typeof(IApiActionFilter))]
public partial class ImageServiceController : BaseApiController
{
protected IntelliTect.SyncUp.Data.Services.ImageService Service { get; }
public ImageServiceController(CrudContext context, IntelliTect.SyncUp.Data.Services.ImageService service) : base(context)
{
GeneratedForClassViewModel = context.ReflectionRepository.GetClassViewModel<IntelliTect.SyncUp.Data.Services.ImageService>();
Service = service;
}
/// <summary>
/// Method: Upload
/// </summary>
[HttpPost("Upload")]
[Authorize]
[Consumes("application/x-www-form-urlencoded", "multipart/form-data")]
public virtual async Task<ItemResult<ImageResponse>> Upload(
[FromForm(Name = "content")] byte[] content)
{
var _params = new
{
Content = content ?? await ((await Request.ReadFormAsync()).Files[nameof(content)]?.OpenReadStream().ReadAllBytesAsync(true) ?? Task.FromResult<byte[]>(null))
};
if (Context.Options.ValidateAttributesForMethods)
{
var _validationResult = ItemResult.FromParameterValidation(
GeneratedForClassViewModel!.MethodByName("Upload"), _params, HttpContext.RequestServices);
if (!_validationResult.WasSuccessful) return new ItemResult<ImageResponse>(_validationResult);
}
IncludeTree includeTree = null;
var _mappingContext = new MappingContext(Context);
var _methodResult = await Service.Upload(
_params.Content
);
var _result = new ItemResult<ImageResponse>(_methodResult);
_result.Object = Mapper.MapToDto<SyncUp.Data.Models.Image, ImageResponse>(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree);
return _result;
}
public class UploadParameters
{
public byte[] Content { get; set; }
}
/// <summary>
/// Method: Upload
/// </summary>
[HttpPost("Upload")]
[Authorize]
[Consumes("application/json")]
public virtual async Task<ItemResult<ImageResponse>> Upload(
[FromBody] UploadParameters _params
)
{
if (Context.Options.ValidateAttributesForMethods)
{
var _validationResult = ItemResult.FromParameterValidation(
GeneratedForClassViewModel!.MethodByName("Upload"), _params, HttpContext.RequestServices);
if (!_validationResult.WasSuccessful) return new ItemResult<ImageResponse>(_validationResult);
}
IncludeTree includeTree = null;
var _mappingContext = new MappingContext(Context);
var _methodResult = await Service.Upload(
_params.Content
);
var _result = new ItemResult<ImageResponse>(_methodResult);
_result.Object = Mapper.MapToDto<SyncUp.Data.Models.Image, ImageResponse>(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree);
return _result;
}
/// <summary>
/// Method: UploadFromUrl
/// </summary>
[HttpPost("UploadFromUrl")]
[Authorize]
[Consumes("application/x-www-form-urlencoded", "multipart/form-data")]
public virtual async Task<ItemResult<ImageResponse>> UploadFromUrl(
[FromForm(Name = "url")] string url)
{
var _params = new
{
Url = url
};
if (Context.Options.ValidateAttributesForMethods)
{
var _validationResult = ItemResult.FromParameterValidation(
GeneratedForClassViewModel!.MethodByName("UploadFromUrl"), _params, HttpContext.RequestServices);
if (!_validationResult.WasSuccessful) return new ItemResult<ImageResponse>(_validationResult);
}
IncludeTree includeTree = null;
var _mappingContext = new MappingContext(Context);
var _methodResult = await Service.UploadFromUrl(
_params.Url
);
var _result = new ItemResult<ImageResponse>(_methodResult);
_result.Object = Mapper.MapToDto<SyncUp.Data.Models.Image, ImageResponse>(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree);
return _result;
}
public class UploadFromUrlParameters
{
public string Url { get; set; }
}
/// <summary>
/// Method: UploadFromUrl
/// </summary>
[HttpPost("UploadFromUrl")]
[Authorize]
[Consumes("application/json")]
public virtual async Task<ItemResult<ImageResponse>> UploadFromUrl(
[FromBody] UploadFromUrlParameters _params
)
{
if (Context.Options.ValidateAttributesForMethods)
{
var _validationResult = ItemResult.FromParameterValidation(
GeneratedForClassViewModel!.MethodByName("UploadFromUrl"), _params, HttpContext.RequestServices);
if (!_validationResult.WasSuccessful) return new ItemResult<ImageResponse>(_validationResult);
}
IncludeTree includeTree = null;
var _mappingContext = new MappingContext(Context);
var _methodResult = await Service.UploadFromUrl(
_params.Url
);
var _result = new ItemResult<ImageResponse>(_methodResult);
_result.Object = Mapper.MapToDto<SyncUp.Data.Models.Image, ImageResponse>(_methodResult.Object, _mappingContext, includeTree ?? _methodResult.IncludeTree);
return _result;
}
}
}