public ActionResult Create(EmpresaModel model) { var session = (Domain.Config.Usuario)Session["Login"]; if (!this.User.Identity.IsAuthenticated || session == null) { return(Logout()); } var data = new byte[] { }; if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any()) { var pic = System.Web.HttpContext.Current.Request.Files["imgBtn"]; using (var inputStream = pic.InputStream) { var memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } data = memoryStream.ToArray(); model.Logotipo = data; } } _companyService.Create(new Domain.Config.Empresa() { Logotipo = model.Logotipo, Nome = model.NomeEmpresa }); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(EmpresaDTO empresa) { if (ModelState.IsValid) { empresa = await _empresaService.Create(this.Usuario, empresa); return(Ok(empresa)); } else { return(BadRequest(ModelState)); } }
public ActionResult Create(JsonHeader collection, HttpPostedFileBase fileXml, HttpPostedFileBase filePdf, HttpPostedFileBase fileCdr, HttpPostedFileBase fileFirma, HttpPostedFileBase fileImage) { Dictionary <string, string> editDictionary = WebHelper.JsonToDictionary(collection.Header); JsonResultMessage jsonResultMessage = new JsonResultMessage(); EmpresaDTO empresaDTO = new EmpresaDTO(); try { if (collection.EditAction == EditActionConstant.EDIT) { empresaDTO.EmpresaId = Convert.ToInt32(editDictionary["EmpresaId"]); } empresaDTO.NumeroRuc = editDictionary["NumeroRuc"].ToString(); empresaDTO.Nombre = editDictionary["Nombre"].ToString(); empresaDTO.RazonSocial = editDictionary["RazonSocial"].ToString(); empresaDTO.Direccion = editDictionary["Direccion"].ToString(); empresaDTO.Telefono = editDictionary["Telefono"].ToString(); empresaDTO.Email = String.Empty; empresaDTO.UsuarioCorreo = editDictionary["UsuarioCorreo"].ToString(); empresaDTO.Correo = editDictionary["Correo"].ToString(); empresaDTO.AliasCorreo = editDictionary["AliasCorreo"].ToString(); empresaDTO.ContrasenaCorreo = editDictionary["ContrasenaCorreo"].ToString(); empresaDTO.ServerSmtp = editDictionary["ServerSmtp"].ToString(); empresaDTO.PuertoSmtp = editDictionary["PuertoSmtp"].ToString(); empresaDTO.SeguridadSsl = false; empresaDTO.UsuarioSunat = editDictionary["UsuarioSunat"].ToString(); empresaDTO.ContrasenaSunat = editDictionary["ContrasenaSunat"].ToString(); empresaDTO.RutaXml = fileXml == null ? string.Empty : Path.GetFileName(fileXml.FileName); empresaDTO.RutaPdf = filePdf == null ? string.Empty : Path.GetFileName(filePdf.FileName); empresaDTO.RutaCrd = fileCdr == null ? string.Empty : Path.GetFileName(fileCdr.FileName); empresaDTO.RutaFirma = fileFirma == null ? string.Empty : Path.GetFileName(fileFirma.FileName); empresaDTO.ContrasenaFirma = editDictionary["ContrasenaFirma"].ToString(); if (fileImage != null) { BinaryReader br = new BinaryReader(fileImage.InputStream); byte[] bytes = br.ReadBytes((int)fileImage.InputStream.Length); // string fil = Path.GetFileName(fileImage.FileName); // string path = Path.Combine(@"D:\FileUpload\firma", fil); empresaDTO.Logo = bytes; //fileImage.SaveAs(path); } if (collection.EditAction == EditActionConstant.NEW) { _empresaService.Create(empresaDTO); } else { _empresaService.Update(empresaDTO); } if (fileXml != null) { string fil = Path.GetFileName(fileXml.FileName); string path = Path.Combine(@"D:\FileUpload\factura", fil); fileXml.SaveAs(path); } if (filePdf != null) { string file = Path.GetFileName(filePdf.FileName); string path = Path.Combine(@"D:\FileUpload\pdf", file); fileXml.SaveAs(path); } if (fileCdr != null) { string fil = Path.GetFileName(fileCdr.FileName); string path = Path.Combine(@"D:\FileUpload\cdr", fil); fileXml.SaveAs(path); } if (fileFirma != null) { string fil = Path.GetFileName(fileFirma.FileName); string path = Path.Combine(@"D:\FileUpload\firma", fil); fileXml.SaveAs(path); } jsonResultMessage.message = "Empresa grabado satisfactoriamente."; } catch (Exception ex) { jsonResultMessage.success = false; jsonResultMessage.message = ex.Message; } return(Json(jsonResultMessage)); }