public virtual ActionResult CreateCompany(CompanyAddViewModel model) { //1048576 Bytes == 1024 * 1024 KB == 1 MB ---> 1024 if (ModelState.IsValid) { try { if (model.Image != null) { if (model.Image.ContentLength > 0) { using (var img = Image.FromStream(model.Image.InputStream)) { string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Company/"), model.Image.FileName); TODO.UploadImage(img, new Size(70, 70), Server.MapPath("~/Content/Images/Company/"), fileName); model.ImageLogo = fileName; } } } model.Title = HelperTitle.GetTitle(Address: model.Address); var company = new Company { Address = model.Address, ImageLogo = model.ImageLogo, Explain = model.Explain, Name = model.Name, Title = model.Title }; _companyService.Create(company); if (_unitOfWork.SaveAllChanges() > 0) { return(RedirectToAction(MVC.admin.Company.ActionNames.DetailsCompany, new { Id = company.Id })); } else { TempData["createCompany"] = Helperalert.alert(new AlertViewModel { Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning }); return(View()); } } catch { TempData["createCompany"] = Helperalert.alert(new AlertViewModel { Alert = AlertOperation.SurveyOperation(StatusOperation.FailInsert), Status = AlertMode.warning }); return(View()); } } else { return(View()); } }
public virtual ActionResult UpdateCompany(CompanyEditViewModel model) { if (ModelState.IsValid) { var company = _companyService.GetById(model.Id); string address = Server.MapPath("~/Content/Images/Company/"); if (model.Image == null) { if (company.ImageLogo != null) { TODO.DeleteImage(Path.Combine(address, company.ImageLogo)); } company.ImageLogo = null; } else { if (company.ImageLogo == null) { } else { TODO.DeleteImage(Path.Combine(address, company.ImageLogo)); } if (model.Image.ContentLength > 0) { using (var img = Image.FromStream(model.Image.InputStream)) { string fileName = TODO.CheckExistFile(Server.MapPath("~/Content/Images/Company/"), model.Image.FileName); TODO.UploadImage(img, new Size(70, 70), Server.MapPath("~/Content/Images/Company/"), fileName); company.ImageLogo = fileName; } } } company.Explain = model.Explain; company.Name = model.Name; if (company.Address != model.Address) { company.Title = HelperTitle.GetTitle(Address: model.Address); company.Address = model.Address; } _companyService.Update(company); if (_unitOfWork.SaveAllChanges() > 0) { return(RedirectToAction(MVC.admin.Company.ActionNames.DetailsCompany, new { Id = model.Id })); } else { TempData["updateCompany"] = Helperalert.alert(new AlertViewModel { Alert = AlertOperation.SurveyOperation(StatusOperation.FailUpdate), Status = AlertMode.warning }); return(View()); } } else { return(View(model)); } }