コード例 #1
0
        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));
        }
コード例 #2
0
        public ActionResult New(CadenaFormModel formModel)
        {
            if (ModelState.IsValid)
            {
                var cadena = new Cadena
                {
                    Nombre         = formModel.Nombre,
                    Descripcion    = formModel.Descripcion,
                    FechaFundacion = formModel.FechaFundacion,
                    CreadoPor      = User.Identity.Name,
                    CreadoEn       = DateTime.Now,
                    ActualizadoPor = User.Identity.Name,
                    ActualizadoEn  = DateTime.Now,
                    Estado         = _statusService.Get(formModel.Estado),
                };

                if (formModel.Logo != null && formModel.Logo.ContentLength > 0)
                {
                    var imageUrl = _blobImageService.UploadImage(formModel.Logo, BlobContainers.General());
                    cadena.Logo = imageUrl;
                }

                if (formModel.Manual != null && formModel.Manual.ContentLength > 0)
                {
                    var manualUrl = _blobImageService.UploadImage(formModel.Manual, BlobContainers.General());
                    cadena.Manual = manualUrl;
                }


                var confirmation = _cadenaService.SaveOrUpdate(cadena);
                if (confirmation.WasSuccessful)
                {
                    this.AddPageMessage("Cadena creada con éxito", PageMessageType.Success, true);
                    return(RedirectToAction("index", "cadenas"));
                }
                else
                {
                    this.AddPageMessage(confirmation.Message, PageMessageType.Error, false);
                }
            }

            PopulateFormModelData(formModel, null);
            return(View(formModel));
        }
コード例 #3
0
        public ActionResult New(GrupoEstandarFormModel formModel)
        {
            if (ModelState.IsValid)
            {
                var grupoEstandar = new GrupoEstandar()
                {
                    Codigo         = formModel.Codigo,
                    Nombre         = formModel.Nombre,
                    CreadoPor      = User.Identity.Name,
                    CreadoEn       = DateTime.Now,
                    ActualizadoPor = User.Identity.Name,
                    ActualizadoEn  = DateTime.Now,
                    Estado         = _statusService.Get(formModel.Estado),
                };

                if (!string.IsNullOrEmpty(formModel.Descripcion))
                {
                    grupoEstandar.Descripcion = formModel.Descripcion;
                }

                if (formModel.Imagen != null && formModel.Imagen.ContentLength > 0)
                {
                    var imageUrl = _blobImageService.UploadImage(formModel.Imagen, BlobContainers.General());
                    grupoEstandar.Imagen = imageUrl;
                }

                var confirmation = _estandarService.SaveOrUpdateGrupo(grupoEstandar);
                if (confirmation.WasSuccessful)
                {
                    this.AddPageMessage("Grupo Estandar creado con éxito", PageMessageType.Success, true);
                    return(RedirectToAction("index", "grupoestandar"));
                }
                else
                {
                    this.AddPageMessage(confirmation.Message, PageMessageType.Error, false);
                }
            }

            PopulateFormModelData(formModel, null);
            return(View(formModel));
        }
コード例 #4
0
        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));
        }