public ActionResult Edit(AboutUsDTO aboutUs) { //get Image have exist var currentFileName = new AboutUsDao(_unitOfWork).GetByid(aboutUs.ID).AboutImage; //check name have deafault if exist ==> dont delete if (aboutUs.FileImage == null) { aboutUs.AboutImage = currentFileName; } else { //delete file var filePath = Server.MapPath(path + currentFileName); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } aboutUs.AboutImage = DateTime.Now.Ticks + Path.GetFileName(aboutUs.FileImage.FileName); aboutUs.FileImage.SaveAs(Server.MapPath(path + aboutUs.AboutImage)); aboutUs.FileImage = null; } var data = new AboutUsDao(_unitOfWork).GetByid(aboutUs.ID); if (!ModelState.IsValid) { return(View(data)); } if (new AboutUsDao(_unitOfWork).Edit(aboutUs)) { return(RedirectToAction("Index")); } TempData[MessageConst.ERROR] = "Edit Failed"; return(View(data)); }
/// <summary> /// Insert Article /// </summary> /// <param name="aboutUs"></param> public void InsertArticle(AboutUsDTO aboutUs) { if (aboutUs == null) { throw new ArgumentNullException("Parameter is null"); } _aboutUsRepository.Insert(_mapper.Map <AboutUs>(aboutUs)); }
public void DeleteAboutUsService(AboutUsDTO entity) { var result = aboutUsRepository.GetAll().Where(r => r.AboutUsId == entity.AboutUsId).FirstOrDefault(); result.AboutUsTitle = entity.AboutUsTitle; result.AboutUsDescription = entity.AboutUsDescription; result.Photo = entity.Photo; aboutUsRepository.Delete(result); }
/// <summary> /// Delete the article /// </summary> /// <param name="aboutUs"></param> public void DeleteAboutUs(AboutUsDTO aboutUs) { if (aboutUs == null) { throw new ArgumentNullException("Parameter is null!"); } aboutUs.IsDeleted = true; UpdateArticle(aboutUs); }
public void AddAboutUsService(AboutUsDTO entity) { AboutUs aboutUs = new AboutUs { AboutUsTitle = entity.AboutUsTitle, AboutUsDescription = entity.AboutUsDescription, Photo = entity.Photo }; aboutUsRepository.Add(aboutUs); }
public bool Edit(AboutUsDTO aboutUs) { try { var data = MapperProfile.MapperConfig().Map <AboutUsDTO, AboutU>(aboutUs); _unitOfWork.AboutUsRepository.Edit(data); return(_unitOfWork.Commit()); } catch (Exception e) { Console.WriteLine(e); return(false); } }
public ActionResult Create(AboutUsDTO aboutUs) { if (aboutUs.FileImage != null) { aboutUs.AboutImage = DateTime.Now.Ticks + Path.GetFileName(aboutUs.FileImage.FileName); aboutUs.FileImage.SaveAs(Server.MapPath(path + aboutUs.AboutImage)); aboutUs.FileImage = null; } if (!ModelState.IsValid) { return(View()); } if (new AboutUsDao(_unitOfWork).Create(aboutUs)) { return(RedirectToAction("Index")); } TempData["error"] = "Create Failed!"; return(View()); }
public ActionResult Index(AboutUsDTO entity) { aboutUsServices.UpdateAboutUsService(entity); //return View(entity); return(Redirect("/Home")); }