public ActionResult New(LocalFormModel formModel) { if (ModelState.IsValid) { var local = new Local() { Codigo = formModel.Codigo, Nombre = formModel.Nombre, Descripcion = formModel.Descripcion, Direccion = formModel.Direccion, Telefono = formModel.Telefono, Email = formModel.Email, Ruc = formModel.Ruc, OpClave = formModel.OpClave, AC = formModel.AC, Concepto = formModel.Concepto, CreadoPor = User.Identity.Name, CreadoEn = DateTime.Now, ActualizadoPor = User.Identity.Name, ActualizadoEn = DateTime.Now, Estado = _statusService.Get(formModel.Estado), TipoLocal = _localService.GetTipo(formModel.TipoLocal), Cadena = _cadenaService.Get(formModel.Cadena), Ciudad = _ubicacionService.GetCiudad(formModel.Ciudad), JefeArea = _jerarquiaService.GetJefeArea(formModel.JefeArea), Propietario = _jerarquiaService.GetJefeArea(formModel.JefeArea).Nombre, }; if (formModel.Imagen != null && formModel.Imagen.ContentLength > 0) { var imageUrl = _blobImageService.UploadImage(formModel.Imagen, BlobContainers.Locales()); local.Imagen = imageUrl; } if (formModel.Logo != null && formModel.Logo.ContentLength > 0) { var logoUrl = _blobImageService.UploadImage(formModel.Logo, BlobContainers.General()); local.Logo = logoUrl; } var confirmation = _localService.SaveOrUpdate(local); if (confirmation.WasSuccessful) { this.AddPageMessage("Local creado con éxito", PageMessageType.Success, true); return(RedirectToAction("index", "locales")); } else { this.AddPageMessage(confirmation.Message, PageMessageType.Error, false); } } PopulateFormModelData(formModel, null); return(View(formModel)); }
public async Task <IHttpActionResult> SaveByLocal([FromBody] ImagenLocalFormModel formModel) { GenericResult itemResult = null; try { if (await _authorizationService.AuthorizeAsync(User)) { var imagenLocal = _localService.GetImage(formModel.Id) ?? new ImagenLocal(); if (imagenLocal.Id == Guid.Empty) { imagenLocal.CreadoEn = DateTime.Now; imagenLocal.CreadoPor = User.Identity.Name; } imagenLocal.ActualizadoEn = DateTime.Now; imagenLocal.ActualizadoPor = User.Identity.Name; imagenLocal.Descripcion = !string.IsNullOrEmpty(formModel.Descripcion) ? formModel.Descripcion : ""; imagenLocal.Tipo = formModel.Tipo; imagenLocal.Orden = formModel.Orden; var local = _localService.Get(formModel.LocalId); imagenLocal.Local = local; if (!string.IsNullOrEmpty(formModel.ImagenData)) { var imageBase64 = formModel.ImagenData.Replace("data:image/jpeg;base64,", ""); var imageBytes = Convert.FromBase64String(imageBase64); var imageUrl = _blobImageService.UploadImage(imageBytes, BlobContainers.Locales()); imagenLocal.Imagen = imageUrl; } ActionConfirmation confirmation = _localService.SaveOrUpdateImagen(imagenLocal); if (confirmation.WasSuccessful) { itemResult = GenericResult.Ok(confirmation.Message); var item = confirmation.Value as ImagenLocal; itemResult.ReturnValue = new { Id = item.Id }; } else { itemResult = GenericResult.Failure(confirmation.Message); } } } catch (Exception exception) { itemResult = GenericResult.Failure(exception.Message); } return(Ok(itemResult)); }