| | | 1 | | using DocumentFormat.OpenXml.Office2016.Drawing.Charts; |
| | | 2 | | using WinSolutions.Sveta.Common.Extensions; |
| | | 3 | | using Microsoft.AspNetCore.Authorization; |
| | | 4 | | using Microsoft.AspNetCore.Mvc; |
| | | 5 | | using Microsoft.Extensions.Logging; |
| | | 6 | | using Microsoft.Extensions.Options; |
| | | 7 | | using Newtonsoft.Json; |
| | | 8 | | using SVETA.Api.Data.Domain; |
| | | 9 | | using SVETA.Api.Data.DTO; |
| | | 10 | | using SVETA.Api.Data.DTO.DepartmentDTO; |
| | | 11 | | using SVETA.Api.Helpers.Authorize; |
| | | 12 | | using SVETA.Api.Services.Interfaces; |
| | | 13 | | using Swashbuckle.AspNetCore.Annotations; |
| | | 14 | | using System; |
| | | 15 | | using System.Collections.Generic; |
| | | 16 | | using System.IO; |
| | | 17 | | using System.Linq; |
| | | 18 | | using System.Threading.Tasks; |
| | | 19 | | using WinSolutions.Sveta.Common; |
| | | 20 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 21 | | using WinSolutions.Sveta.Server.Data.DataModel.Extensions; |
| | | 22 | | using WinSolutions.Sveta.Server.Data.DataModel.Kinds; |
| | | 23 | | using WinSolutions.Sveta.Server.Domain; |
| | | 24 | | using WinSolutions.Sveta.Server.Services.Interfaces; |
| | | 25 | | |
| | | 26 | | namespace SVETA.Api.Controllers |
| | | 27 | | { |
| | | 28 | | [Authorize] |
| | | 29 | | [Route("api/v1/GoodSettings")] |
| | | 30 | | [ApiController] |
| | | 31 | | public class GoodSettingsController : SvetaController |
| | | 32 | | { |
| | | 33 | | const string _routeUrl = "api/v1/GoodSettings"; |
| | | 34 | | readonly IDepartmentService _departmentService; |
| | | 35 | | private readonly IAuthenticationService _authUserService; |
| | | 36 | | private readonly IGoodLabelService _labelService; |
| | | 37 | | private readonly IUploadWorker _uploadWorker; |
| | | 38 | | readonly ILogger<GoodSettingsController> _logger; |
| | | 39 | | readonly IGoodSettingService _serviceGoodSetting; |
| | | 40 | | readonly IGoodService _goodService; |
| | | 41 | | IDiskStorageService _diskStorage; |
| | | 42 | | private readonly ImagesSettings _imageSettings; |
| | | 43 | | |
| | | 44 | | public GoodSettingsController( |
| | | 45 | | IDepartmentService departmentService, |
| | | 46 | | IAuthenticationService authUserService, |
| | | 47 | | IGoodSettingService serviceGoodSetting, |
| | | 48 | | IGoodLabelService labelService, |
| | | 49 | | IGoodService goodService, |
| | | 50 | | IOptions<ImagesSettings> options, |
| | | 51 | | IDiskStorageService diskStorage, |
| | | 52 | | IUploadWorker uploadWorker, |
| | 0 | 53 | | ILogger<GoodSettingsController> logger) : base(logger) |
| | 0 | 54 | | { |
| | 0 | 55 | | _uploadWorker = uploadWorker; |
| | 0 | 56 | | _labelService = labelService; |
| | 0 | 57 | | _authUserService = authUserService; |
| | 0 | 58 | | _departmentService = departmentService; |
| | 0 | 59 | | _serviceGoodSetting = serviceGoodSetting; |
| | 0 | 60 | | _goodService = goodService; |
| | 0 | 61 | | _logger = logger; |
| | 0 | 62 | | _imageSettings = options.Value; |
| | 0 | 63 | | _diskStorage = diskStorage; |
| | 0 | 64 | | } |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Получить все настройки мин. партия и квант поставки по всем подразделениям и товарам |
| | | 68 | | /// </summary> |
| | | 69 | | /// <remarks>author i.rebenok</remarks> |
| | | 70 | | /// <param name="page">Любое значение ниже нуля изменится на 1, пагинация: номер страницы</param> |
| | | 71 | | /// <param name="limit">Любое значение ниже нуля изменится на 10, пагинация: размер страницы</param> |
| | | 72 | | /// <param name="filter">фильтр по значимым полям: артикул или название товара</param> |
| | | 73 | | /// <param name="labelId">ярлык товара: 0 - все ярлыки (по-умолчанию), >0 - конкретный ярлык</param> |
| | | 74 | | /// <param name="categoryId">категория товара. 0 - все категории (по-умолчанию), >0 - конкретная категория</para |
| | | 75 | | /// <param name="departmentId">Департамент. 0 - все департаменты (по-умолчанию), >0 - конкретный департамент</pa |
| | | 76 | | /// <param name="sort">сортировка по одному из полей |
| | | 77 | | /// по vencode,vencode|desc, name,name|desc, minQuant,minQuant|desc, pickQuant,pickQuant|desc. Сортировка по умо |
| | | 78 | | [HttpGet("")] |
| | | 79 | | [SwaggerResponse(200, "Успешно", typeof(BaseResponseDTO<GoodSettingResponseDTO>))] |
| | | 80 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 81 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 82 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 83 | | [Authorize (Roles =Role.SystemAdmin +"," + Role.SystemOperator + "," +Role.SupplierOwner + "," +Role.SupplierOpe |
| | | 84 | | public async Task<IActionResult> GetDepartmentsGoodSettings(int page = 1, int limit = 10, long labelId = 0, long |
| | 0 | 85 | | { |
| | 0 | 86 | | filter = filter.NormalizeName(); |
| | 0 | 87 | | page = page < 1 ? 1 : page; |
| | 0 | 88 | | limit = limit < 1 ? 10 : limit; |
| | 0 | 89 | | if (!_authUserService.IsUserPlatform() && await _departmentService.GetDepartment(departmentId, _authUserServ |
| | 0 | 90 | | return NotFoundResult($"Подразделение с id={departmentId} не найдено"); |
| | 0 | 91 | | var data = await _serviceGoodSetting.GetDepartmentsGoodSettings(page - 1, limit, labelId, categoryId, depart |
| | 0 | 92 | | data.Result.ForEach(g => g.Good.Photos.SetPhotoUrl(_imageSettings)); |
| | 0 | 93 | | var param = $"sort={sort}&departmentId={departmentId}&categoryId={categoryId}"; |
| | 0 | 94 | | var response = new BaseResponseDTO<GoodSettingResponseDTO>(_routeUrl, page, (int)limit, data.TotalFilteredCo |
| | 0 | 95 | | { |
| | 0 | 96 | | Data = data.Result.Select(x => new GoodSettingResponseDTO(x)).ToList(), |
| | 0 | 97 | | }; |
| | 0 | 98 | | return Ok(response); |
| | 0 | 99 | | } |
| | | 100 | | |
| | | 101 | | /// <summary> |
| | | 102 | | /// Список-источник товаров для добавления в сеттинг |
| | | 103 | | /// </summary> |
| | | 104 | | /// <remarks>author: i.rebenok</remarks> |
| | | 105 | | /// <param name="page">Любое значение ниже нуля изменится на 1, пагинация: номер страницы</param> |
| | | 106 | | /// <param name="limit">Любое значение ниже нуля изменится на 10, пагинация: размер страницы</param> |
| | | 107 | | /// <param name="filter">фильтр по названиям или коду товара</param> |
| | | 108 | | /// <param name="categoryId">0 - все категории, иначе конкретная. 0 по умолчанию</param> |
| | | 109 | | /// <param name="departmentId">id подразделения</param> |
| | | 110 | | /// <param name="sort">сортировка по одному из полей |
| | | 111 | | /// по code,code|desc, name,name|desc. Сортировка по умолчанию по name</param> |
| | | 112 | | [HttpGet("{departmentId}/SourceGoods")] |
| | | 113 | | [SwaggerResponse(200, "Успешно", typeof(BaseResponseDTO<GoodSettingsSourceGoodsResponseDTO>))] |
| | | 114 | | [SwaggerResponse(404, "Нет записей", typeof(EmptyResult))] |
| | | 115 | | [SwaggerResponse(403, "Не разрешено для этого пользователя")] |
| | | 116 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(string))] |
| | | 117 | | [Authorize(Roles = Role.SystemAdmin + "," + Role.SystemOperator + "," + Role.SupplierOwner + "," + Role.Supplier |
| | | 118 | | public async Task<IActionResult> GetSourceGoods(long departmentId, int page = 1, int limit = 10, long categoryId |
| | 0 | 119 | | { |
| | 0 | 120 | | filter = filter.NormalizeName(); |
| | 0 | 121 | | if (!_authUserService.IsUserPlatform() && await _departmentService.GetDepartment(departmentId, _authUserServ |
| | 0 | 122 | | return NotFoundResult($"Подразделение с id={departmentId} не найдено"); |
| | 0 | 123 | | var settings = await _serviceGoodSetting.GetDepartmentGoodSettings(departmentId); |
| | 0 | 124 | | if (settings == null) |
| | 0 | 125 | | return NotFoundResult($"Не найдено настроек для подразделения с id={departmentId}"); |
| | 0 | 126 | | var goods = await _goodService.GetActiveGoods(page-1,limit, departmentId,categoryId, sort, filter); |
| | 0 | 127 | | goods.Result.ForEach(g => g.Photos.SetPhotoUrl(_imageSettings)); |
| | 0 | 128 | | var param = $"departmentId={departmentId}&categoryId={categoryId}&sort={sort}"; |
| | 0 | 129 | | var response = new BaseResponseDTO<GoodSettingsSourceGoodsResponseDTO>(_routeUrl+"/"+ departmentId+ "/Source |
| | 0 | 130 | | { |
| | 0 | 131 | | Data = goods.Result.Select(x => new GoodSettingsSourceGoodsResponseDTO() |
| | 0 | 132 | | { |
| | 0 | 133 | | Id = x.Id, |
| | 0 | 134 | | VendorCode = x.GetActualVendorCode(departmentId), |
| | 0 | 135 | | UniqueCode = x.UniqueCode, |
| | 0 | 136 | | Name = x.Name, |
| | 0 | 137 | | IsInSetting = (settings.Any(d => d.Good.Id == x.Id && !d.IsDeleted) ? true : false), |
| | 0 | 138 | | SettingId = settings.FirstOrDefault(d => d.Good.Id == x.Id)?.Id, |
| | 0 | 139 | | Photo = (PhotoPrevDto)x.Photos.FirstOrDefault() |
| | 0 | 140 | | }).ToList(), |
| | 0 | 141 | | }; |
| | 0 | 142 | | return Ok(response); |
| | 0 | 143 | | } |
| | | 144 | | |
| | | 145 | | /// <summary> |
| | | 146 | | /// Создать настройку мин. партия и квант поставки для одного подразделения по одному товару |
| | | 147 | | /// </summary> |
| | | 148 | | /// <remarks>author i.rebenok</remarks> |
| | | 149 | | /// <param name="data">объект DepartmentGoodSettingRequestDTO_POST. Параметр ShowcaseVisible в объекте Departmen |
| | | 150 | | [HttpPost("")] |
| | | 151 | | [SwaggerResponse(201, "Успешно создано", typeof(GoodSettingResponseDTO))] |
| | | 152 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 153 | | [SwaggerResponse(400, "Некорректные входные данные", typeof(ErrorDTO))] |
| | | 154 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 155 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 156 | | [Authorize(Roles = Role.SystemAdmin + "," + Role.SupplierOwner + "," + Role.SupplierOperator)] |
| | | 157 | | public async Task<IActionResult> PostDepartmentGoodSetting([FromBody] [SwaggerParameter(Required = true)] Depart |
| | 0 | 158 | | { |
| | 0 | 159 | | if (!ModelState.IsValid) |
| | 0 | 160 | | { |
| | 0 | 161 | | return BadRequestResult("Некорректные входные данные"); |
| | | 162 | | } |
| | | 163 | | |
| | 0 | 164 | | var department = _authUserService.IsUserPlatform() ? await _departmentService.GetDepartment(data.DepartmentI |
| | 0 | 165 | | await _departmentService.GetDepartment(data.DepartmentId, _authUserService.ContragentId); |
| | 0 | 166 | | var good = await _goodService.GetGood(data.GoodId); |
| | | 167 | | |
| | 0 | 168 | | if (department == null) |
| | 0 | 169 | | return NotFoundResult($"Подразделение c id={data.DepartmentId} не найдено"); |
| | 0 | 170 | | if (good == null) |
| | 0 | 171 | | return NotFoundResult($"Товар с id={data.GoodId} не найден"); |
| | | 172 | | |
| | 0 | 173 | | var newSetting = new DepartmentGoodSetting |
| | 0 | 174 | | { |
| | 0 | 175 | | Department = department, |
| | 0 | 176 | | Good = good, |
| | 0 | 177 | | MinQuantity = 1, |
| | 0 | 178 | | PickingQuantum = 1, |
| | 0 | 179 | | VendorCode = data.VendorCode, |
| | 0 | 180 | | ShowcaseVisible = data.ShowcaseVisible |
| | 0 | 181 | | }; |
| | 0 | 182 | | newSetting = await _serviceGoodSetting.Create(newSetting); |
| | 0 | 183 | | return StatusCode(201, new GoodSettingResponseDTO(newSetting)); |
| | 0 | 184 | | } |
| | | 185 | | |
| | | 186 | | /// <summary> |
| | | 187 | | /// Обновление мин. партия и квант поставки по одному товару в подразделении |
| | | 188 | | /// </summary> |
| | | 189 | | /// <remarks>author i.rebenok</remarks> |
| | | 190 | | /// <param name="id">id записи </param> |
| | | 191 | | /// <param name="data">DepartmentGoodSettingRequestDTO_PUT</param> |
| | | 192 | | [HttpPut("{id}")] |
| | | 193 | | [SwaggerResponse(200, "Успешно обновлено", typeof(GoodSettingResponseDTO))] |
| | | 194 | | [SwaggerResponse(400, "Некорректные входные данные", typeof(ErrorDTO))] |
| | | 195 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 196 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 197 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 198 | | [Authorize(Roles = Role.SystemAdmin+ "," + Role.SupplierOwner + "," + Role.SupplierOperator)] |
| | | 199 | | public async Task<IActionResult> PutDepartmentGoodSetting([SwaggerParameter(Required = true)]long id, [FromBody] |
| | 0 | 200 | | { |
| | 0 | 201 | | if (!ModelState.IsValid) |
| | 0 | 202 | | { |
| | 0 | 203 | | return BadRequestResult(""); |
| | | 204 | | } |
| | 0 | 205 | | var item = await _serviceGoodSetting.GetDepartmentGoodSetting(id); |
| | | 206 | | |
| | 0 | 207 | | if (item == null || (item.Department.Contragent?.Id != _authUserService.ContragentId && !_authUserService.Is |
| | 0 | 208 | | return NotFoundResult($"Настройки товара с id={id} не найдены"); |
| | | 209 | | |
| | 0 | 210 | | item.MinQuantity = data.MinQuantity > 0 ? data.MinQuantity : item.MinQuantity; |
| | 0 | 211 | | item.PickingQuantum = data.PickingQuantum > 0 ? data.PickingQuantum : item.PickingQuantum; |
| | 0 | 212 | | item.VendorCode = data.VendorCode; |
| | 0 | 213 | | item.ShowcaseVisible = data.ShowcaseVisible; |
| | | 214 | | |
| | 0 | 215 | | await _serviceGoodSetting.Update(item); |
| | | 216 | | |
| | | 217 | | //попросили сделать так. Сперва обновляем что можно, а на остальное выдаем ошибку |
| | 0 | 218 | | if (data.MinQuantity <= 0) |
| | 0 | 219 | | return BadRequestResult("Минимальная партия отборки не может быть меньше 1"); |
| | 0 | 220 | | if (data.PickingQuantum <= 0) |
| | 0 | 221 | | return BadRequestResult("Квант отборки не может быть меньше 1"); |
| | | 222 | | |
| | 0 | 223 | | return Ok(new GoodSettingResponseDTO(item)); |
| | 0 | 224 | | } |
| | | 225 | | |
| | | 226 | | /// <summary> |
| | | 227 | | /// Удаление записи по id |
| | | 228 | | /// </summary> |
| | | 229 | | /// <remarks>author i.rebenok</remarks> |
| | | 230 | | /// <param name="id">id удаляемой записи о настройках</param> |
| | | 231 | | [HttpDelete("{id}")] |
| | | 232 | | [SwaggerResponse(200, "Успешно удалено", typeof(EmptyResult))] |
| | | 233 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 234 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 235 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 236 | | [Authorize(Roles = Role.SystemAdmin + "," + Role.SupplierOwner + "," + Role.SupplierOperator)] |
| | | 237 | | public async Task<IActionResult> DeleteDepartmentGoodSetting([SwaggerParameter(Required = true)] long id) |
| | 0 | 238 | | { |
| | 0 | 239 | | var item = await _serviceGoodSetting.GetDepartmentGoodSetting(id); |
| | | 240 | | |
| | 0 | 241 | | if (item == null || (item.Department.Contragent?.Id != _authUserService.ContragentId && !_authUserService.Is |
| | 0 | 242 | | return NotFoundResult($"Настройки товара с id={id} не найдены"); |
| | | 243 | | |
| | 0 | 244 | | await _serviceGoodSetting.Delete(id); |
| | 0 | 245 | | return Ok(); |
| | 0 | 246 | | } |
| | | 247 | | |
| | | 248 | | /// <summary> |
| | | 249 | | /// Удаление записи по id товара и id департамента |
| | | 250 | | /// </summary> |
| | | 251 | | /// <remarks>author i.rebenok</remarks> |
| | | 252 | | /// <param name="goodId">id товара</param> |
| | | 253 | | /// <param name="departmentId">id склада</param> |
| | | 254 | | [HttpDelete("{departmentId}/Good/{goodId}")] |
| | | 255 | | [SwaggerResponse(200, "Успешно удалено", typeof(EmptyResult))] |
| | | 256 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 257 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 258 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 259 | | [Authorize(Roles = Role.SystemAdmin + "," + Role.SupplierOwner + "," + Role.SupplierOperator)] |
| | | 260 | | public async Task<IActionResult> DeleteDepartmentGoodSetting([SwaggerParameter(Required = true)] long goodId, [S |
| | 0 | 261 | | { |
| | 0 | 262 | | var item = await _serviceGoodSetting.GetDepartmentGoodSetting(departmentId, goodId); |
| | | 263 | | |
| | 0 | 264 | | if (item == null || (item.Department.Contragent?.Id != _authUserService.ContragentId && !_authUserService.Is |
| | 0 | 265 | | return NotFoundResult($"Запись с id товара {goodId} и складом {departmentId} не найдена"); |
| | | 266 | | |
| | 0 | 267 | | await _serviceGoodSetting.Delete(item.Id); |
| | 0 | 268 | | return Ok(); |
| | 0 | 269 | | } |
| | | 270 | | |
| | | 271 | | /// <summary> |
| | | 272 | | /// Экспортирует в файл |
| | | 273 | | /// </summary> |
| | | 274 | | /// <param name="departmentId">id склада, 0 для всех</param> |
| | | 275 | | /// <returns></returns> |
| | | 276 | | [HttpGet("Export/{departmentId}")] |
| | | 277 | | [SwaggerResponse(200, "Успешно", typeof(File))] |
| | | 278 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 279 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 280 | | [Authorize(Roles = Role.SystemAdmin + "," + Role.SystemOperator + "," + Role.SupplierOwner + "," + Role.Supplier |
| | | 281 | | public async Task<IActionResult> Export([SwaggerParameter(Required = true)] long departmentId) |
| | 0 | 282 | | { |
| | 0 | 283 | | if(!User.IsInRole(Role.SystemAdmin)) |
| | 0 | 284 | | { |
| | 0 | 285 | | if (!_authUserService.IsUserPlatform() && await _departmentService.GetDepartment(departmentId, _authUser |
| | 0 | 286 | | { |
| | 0 | 287 | | throw new KeyNotFoundException($"Подразделение с id={departmentId} не найдено"); |
| | | 288 | | } |
| | 0 | 289 | | } |
| | | 290 | | |
| | 0 | 291 | | var result = await _uploadWorker.DownloadGoodSettingsToFile(departmentId); |
| | 0 | 292 | | _diskStorage.SaveDownload("good_settings.xlsx", result, out string fileName); |
| | 0 | 293 | | return File(result, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Path.GetFileName(fi |
| | 0 | 294 | | } |
| | | 295 | | |
| | | 296 | | /// <summary> |
| | | 297 | | /// Привязывает ярлык к сеттингу |
| | | 298 | | /// </summary> |
| | | 299 | | /// <remarks>author i.rebenok</remarks> |
| | | 300 | | /// <param name="id">id сеттинга</param> |
| | | 301 | | /// <param name="labelId">id ярлыка</param> |
| | | 302 | | [HttpPut("Labels/{id}/Bind")] |
| | | 303 | | [SwaggerResponse(200, "Успешно", typeof(EmptyResult))] |
| | | 304 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 305 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 306 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 307 | | [Authorize(Roles = Role.SystemAdmin + "," + Role.SupplierOwner + "," + Role.SupplierOperator)] |
| | | 308 | | public async Task<IActionResult> BindLabelToSetting([SwaggerParameter(Required = true)] long id, [FromBody] [Swa |
| | | 309 | | { |
| | | 310 | | var setting = await _serviceGoodSetting.GetDepartmentGoodSetting(id); |
| | | 311 | | if (setting == null || (setting.Department.Contragent?.Id != _authUserService.ContragentId && !_authUserServ |
| | | 312 | | return NotFoundResult($"Настройки товара с id={id} не найдены"); |
| | | 313 | | var label = await _labelService.GetGoodLabel(labelId); |
| | | 314 | | if (label == null) |
| | | 315 | | return NotFoundResult($"Ярлык с id={labelId} не найден"); |
| | 0 | 316 | | if (!setting.GoodSettingsLabels.Any(x => x.GoodLabelId == labelId)) |
| | | 317 | | { |
| | | 318 | | setting.GoodSettingsLabels.Add(new GoodSettingsLabel { GoodLabelId = labelId }); |
| | | 319 | | await _serviceGoodSetting.Update(setting); |
| | | 320 | | } |
| | | 321 | | return Ok(); |
| | | 322 | | } |
| | | 323 | | |
| | | 324 | | /// <summary> |
| | | 325 | | /// Отвязывает ярлык от сеттинга |
| | | 326 | | /// </summary> |
| | | 327 | | /// <remarks>author i.rebenok</remarks> |
| | | 328 | | /// <param name="id">id сеттинга</param> |
| | | 329 | | /// <param name="labelId">id ярлыка</param> |
| | | 330 | | [HttpPut("Labels/{id}/UnBind")] |
| | | 331 | | [SwaggerResponse(200, "Успешно", typeof(EmptyResult))] |
| | | 332 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 333 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 334 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 335 | | [Authorize(Roles = Role.SystemAdmin + "," + Role.SupplierOwner + "," + Role.SupplierOperator)] |
| | | 336 | | public async Task<IActionResult> UnbindLabelFromSetting([SwaggerParameter(Required = true)] long id, [FromBody][ |
| | | 337 | | { |
| | | 338 | | var setting = await _serviceGoodSetting.GetDepartmentGoodSetting(id); |
| | | 339 | | if (setting == null || (setting.Department.Contragent?.Id != _authUserService.ContragentId && !_authUserServ |
| | | 340 | | return NotFoundResult($"Настройки товара с id={id} не найдены"); |
| | | 341 | | var label = await _labelService.GetGoodLabel(labelId); |
| | | 342 | | if (label == null) |
| | | 343 | | return NotFoundResult($"Ярлык с id={labelId} не найден"); |
| | 0 | 344 | | if (setting.GoodSettingsLabels.Any(x => x.GoodLabelId == labelId)) |
| | | 345 | | { |
| | 0 | 346 | | setting.GoodSettingsLabels.Remove(setting.GoodSettingsLabels.FirstOrDefault(x => x.GoodLabelId == labelI |
| | | 347 | | await _serviceGoodSetting.Update(setting); |
| | | 348 | | } |
| | | 349 | | return Ok(); |
| | | 350 | | } |
| | | 351 | | |
| | | 352 | | /// <summary> |
| | | 353 | | /// Меняет видимость товара на витрине |
| | | 354 | | /// </summary> |
| | | 355 | | /// <remarks>author i.rebenok</remarks> |
| | | 356 | | /// <param name="data">Объект с настройкой видимости и списком id записей настроек товаров</param> |
| | | 357 | | [HttpPut("Visibility")] |
| | | 358 | | [SwaggerResponse(200, "Успешно", typeof(EmptyResult))] |
| | | 359 | | [SwaggerResponse(404, "Нет записей", typeof(ErrorDTO))] |
| | | 360 | | [SwaggerResponse(500, "Ошибка на стороне сервера", typeof(ErrorDTO))] |
| | | 361 | | [SwaggerResponse(403, "Не разрешено для этого пользователя", typeof(ErrorDTO))] |
| | | 362 | | [Authorize(Roles = Role.SystemAdmin + "," + Role.SupplierOwner + "," + Role.SupplierOperator)] |
| | | 363 | | public async Task<IActionResult> UnbindLabelFromSetting([FromBody] DepartmentGoodSettingVisibilityDTO data) |
| | | 364 | | { |
| | | 365 | | var settings = await _serviceGoodSetting.GetDepartmentsGoodSettings(data.Itemids) ?? throw new ArgumentExcep |
| | 0 | 366 | | if (!_authUserService.IsUserPlatform() && settings.Any(x => x.Department.Contragent.Id != _authUserService.C |
| | | 367 | | return ForbidResult("Не хватает прав для внесения изменений"); |
| | | 368 | | foreach (var setting in settings) |
| | | 369 | | setting.ShowcaseVisible = data.Visibility; |
| | | 370 | | await _serviceGoodSetting.Update(settings); |
| | | 371 | | return Ok(); |
| | | 372 | | } |
| | | 373 | | } |
| | | 374 | | } |