public ActionResult EditWorker(WorkersViewModel wvm) { if (ModelState.IsValid) { var worker = _uow.Workers.Get(wvm.Id); var dept = _uow.Departments.Find(s => s.Name == wvm.DepartmentName).FirstOrDefault(); if (worker != null) { string fileName = Path.GetFileNameWithoutExtension(wvm.ImageFile.FileName); string extension = Path.GetExtension(wvm.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssffff") + extension; wvm.ImageUrl = fileName; fileName = Path.Combine(Server.MapPath("~/Content/Images/"), fileName); worker.WorkerName = wvm.FirstName + "" + wvm.LastName + "" + wvm.OtherName; worker.PhoneNumber = wvm.PhoneNumber; worker.Address = wvm.Address; worker.ImageUrl = wvm.ImageUrl; worker.ImageThumbnailUrl = wvm.ImageUrl; if (wvm.ImageFile != null && wvm.ImageFile.ContentLength > 0) { wvm.ImageFile.SaveAs(fileName); } worker.Department = dept; _uow.Commit(); TempData["message"] = $"{worker.WorkerName} was successfully edited "; } return(RedirectToAction("Index")); } else { return(View(wvm)); } }
public ActionResult EditWorker(int id) { var worker = _uow.Workers.Get(id); var dept = _uow.Departments.GetAll(); var dep = worker.Department; ViewBag.workerdept = new SelectList(dept, "Name", "Name", dep.Name); var wvm = new WorkersViewModel { FirstName = worker.WorkerName, Address = worker.Address, DepartmentName = worker.Department.Name, PhoneNumber = worker.PhoneNumber, ImageUrl = worker.ImageUrl }; return(View(wvm)); }
public ActionResult JoinWorker(WorkersViewModel dcvm) { if (ModelState.IsValid) { var dept = _uow.Departments.Find(r => r.Name == dcvm.DepartmentName).FirstOrDefault(); string fileName = Path.GetFileNameWithoutExtension(dcvm.ImageFile.FileName); string extension = Path.GetExtension(dcvm.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssffff") + extension; dcvm.ImageUrl = fileName; fileName = Path.Combine(Server.MapPath("~/Content/Images/"), fileName); dcvm.ImageFile.SaveAs(fileName); string file = Path.GetFileNameWithoutExtension(dcvm.FilethunmbnailUrl.FileName); string fileextension = Path.GetExtension(dcvm.FilethunmbnailUrl.FileName); file = fileName + DateTime.Now.ToString("yymmssffff") + extension; dcvm.FileUrl = file; fileName = Path.Combine(Server.MapPath("~/Content/Images/"), file); dcvm.FilethunmbnailUrl.SaveAs(file); var worker = new Worker { WorkerName = dcvm.FirstName + " " + dcvm.LastName, BaptismDate = dcvm.BaptismDate, HolyGhostBaptism = dcvm.HolyGhostBaptism, IsMarried = dcvm.IsMarried, WaterBaptism = dcvm.WaterBaptism, JoinDate = dcvm.JoinDate, Address = dcvm.Address, Department = dept, ImageUrl = dcvm.ImageUrl, ImageThumbnailUrl = dcvm.ImageUrl, PhoneNumber = dcvm.PhoneNumber, Experience = dcvm.Experience, FileUrl = dcvm.FileUrl, FilethunmbnailUrl = dcvm.FileUrl, SpouseName = dcvm.SpouseName, NumberOfChildren = dcvm.NumberOfChildren, MarriageAnniversary = dcvm.MarriageAnniversary, Profession = dcvm.Profession, ChurchBaptised = dcvm.ChurchBaptised, BornAgain = dcvm.BornAgain, YearBornAgain = dcvm.YearBornAgain, IsExperienced = dcvm.IsExperienced, BirthDate = dcvm.BirthDate, SOD = dcvm.SOD, SODYear = dcvm.SODYear, SOM = dcvm.SOM, SOMYear = dcvm.SOMYear, BC = dcvm.BC }; _uow.Workers.Add(worker); _uow.Commit(); TempData["message"] = string.Format("{0} has been saved.", dcvm.FirstName); return(RedirectToAction("Index", "Home")); } else { var dept = _uow.Departments.GetAll().Select(r => r.Name); ViewBag.Department = new SelectList(dept); return(View(dcvm)); } }