public async Task <IActionResult> Edit(long?id) { if (id == null) { return(NotFound()); } var item = await profileCardBusinessService.GetProfileCard(id ?? 0); if (item == null) { return(NotFound()); } // devices var devices = await locationService.GetDevices(); var deviceList = new List <SelectListItem>(); deviceList.Add(new SelectListItem { Value = "", Text = "Выберите значение" }); deviceList.AddRange(devices.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Imei }).ToList()); ViewBag.Devices = deviceList; var model = Mapper.Map <ProfileViewModel>(item); return(View(model)); }
public async Task <IActionResult> MediaUpload(long id) { var files = Request.Form.Files; if (files == null || files.Count == 0) { return(BadRequest("Файлы не загружены")); } var item = await profileCardBusinessService.GetProfileCard(id); if (item == null) { return(BadRequest("Не найден идентификатор")); } long size = files.Sum(f => f.Length); var result = new List <ProfileCardMediaDto>(); foreach (var formFile in files) { if (formFile.Length > 0) { using (var memoryStream = new MemoryStream()) { await formFile.CopyToAsync(memoryStream, new System.Threading.CancellationToken()); var pitem = await profileCardBusinessService.AddProfileCardMedia("", id, new ProfileCardMediaDto() { ProfileCardId = id, Source = memoryStream.ToArray(), ContentType = formFile.ContentType, Name = formFile.Name }); if (pitem != null) { result.Add(pitem); } } } } return(Ok(result)); }