public async Task Edit(string hallId, StandViewModel stand, IFormFile file, IEnumerable <string> exhibits, byte[] photo) { var initialStand = await _standsRepository.GetAsync(hallId, stand.Id); stand.Exhibits = new List <ExhibitViewModel>(); foreach (var id in exhibits) { stand.Exhibits.Add(initialStand.Exhibits.First(e => e.Id.Equals(id))); } if (initialStand.Photo != null) { stand.Photo = initialStand.Photo; if (photo == null) { stand.Photo.Photo = null; } } if (file != null) { await _formFileToByteConverterService.ConvertAsync(file, stand); } await _standsRepository.UpdateAsync(hallId, stand.Id, stand); }
public async Task UpdateAsync(string hallId, string id, StandViewModel stand) { if (!string.IsNullOrEmpty(stand.Photo?.Id)) { await _gridFS.DeleteAsync(ObjectId.Parse(stand.Photo.Id)); } if (stand.Photo?.Photo != null) { ObjectId photoId = await _gridFS.UploadFromBytesAsync(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff"), stand.Photo.Photo); stand.Photo.Id = photoId.ToString(); stand.Photo.Photo = null; } else { stand.Photo = null; } var arrayFilter = Builders <HallViewModel> .Filter.And( Builders <HallViewModel> .Filter.Where(hall => hall.Id.Equals(hallId)), Builders <HallViewModel> .Filter.Eq("Stands.Id", id)); var update = Builders <HallViewModel> .Update.Set("Stands.$", stand); await _halls.UpdateOneAsync(arrayFilter, update); }
public async Task <string> Create(string hallId, StandViewModel stand, IFormFile file) { if (file != null) { await _formFileToByteConverterService.ConvertAsync(file, stand); } stand.Exhibits = new List <ExhibitViewModel>(); return(await _standsRepository.CreateAsync(hallId, stand)); }
// GET: Stand public ActionResult Nuevo() { var modelCampanas = Mapper.Map <IList <CampanaDto>, IList <CampanaViewModel> >(servicioCampanas.Buscar(String.Empty)); var modelClientes = Mapper.Map <IList <ClienteDto>, IList <ClienteViewModel> >(servicioClientes.Buscar(String.Empty)); var model = new StandViewModel { Campaña = new SelectList(modelCampanas, "Id", "Nombre"), Cliente = new SelectList(modelClientes, "Id", "RazonSocial") }; return(View(model)); }
public async Task ConvertAsync(IFormFile file, StandViewModel stand) { using (var memoryStream = new MemoryStream()) { await file.CopyToAsync(memoryStream); if (stand.Photo == null) { stand.Photo = new PhotoInfo(); } stand.Photo.Photo = memoryStream.ToArray(); } }
public ActionResult Nuevo(StandViewModel stand) { try { if (ModelState.IsValid) { StandDto standDto = Mapper.Map <StandViewModel, StandDto>(stand); servicioStands.Nuevo(standDto); return(RedirectToAction("Index", "Campanas", new { area = "" })); } ModelState.AddModelError("", "Hubo Error en el Modelo"); return(View(stand)); } catch (Exception) { throw; } }
public async Task <string> CreateAsync(string hallId, StandViewModel stand) { if (stand.Photo?.Photo != null) { ObjectId id = await _gridFS.UploadFromBytesAsync(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff"), stand.Photo.Photo); stand.Photo.Id = id.ToString(); stand.Photo.Photo = null; } stand.Id = ObjectId.GenerateNewId().ToString(); var filter = Builders <HallViewModel> .Filter.Eq("Id", hallId); var update = Builders <HallViewModel> .Update.Push("Stands", stand); await _halls.UpdateOneAsync(filter, update); return(stand.Id); }