Пример #1
0
        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));
            }
        }
Пример #2
0
        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));
        }
Пример #3
0
        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);

                if (dcvm.SODCert != null)
                {
                    string SODfile          = Path.GetFileNameWithoutExtension(dcvm.SODCert.FileName);
                    string SODfileextension = Path.GetExtension(dcvm.SODCert.FileName);
                    SODfile     = SODfile + DateTime.Now.ToString("yymmssffff") + SODfileextension;
                    dcvm.SODUrl = SODfile;
                    SODfile     = Path.Combine(Server.MapPath("~/Content/Images/"), SODfile);
                    dcvm.SODCert.SaveAs(SODfile);
                }

                if (dcvm.BCCert != null)
                {
                    string BCfile          = Path.GetFileNameWithoutExtension(dcvm.BCCert.FileName);
                    string BCfileextension = Path.GetExtension(dcvm.BCCert.FileName);
                    BCfile     = BCfile + DateTime.Now.ToString("yymmssffff") + BCfileextension;
                    dcvm.BCUrl = BCfile;
                    BCfile     = Path.Combine(Server.MapPath("~/Content/Images/"), BCfile);
                    dcvm.BCCert.SaveAs(BCfile);
                }
                if (dcvm.BaptismCert != null)
                {
                    string Baptismfile          = Path.GetFileNameWithoutExtension(dcvm.BaptismCert.FileName);
                    string Baptismfileextension = Path.GetExtension(dcvm.BaptismCert.FileName);
                    Baptismfile     = Baptismfile + DateTime.Now.ToString("yymmssffff") + Baptismfileextension;
                    dcvm.BaptismUrl = Baptismfile;
                    Baptismfile     = Path.Combine(Server.MapPath("~/Content/Images/"), Baptismfile);
                    dcvm.BCCert.SaveAs(Baptismfile);
                }

                var worker = new Worker
                {
                    BCUrl  = dcvm.BCUrl,
                    BCCert = dcvm.BCUrl,

                    BaptismUrl          = dcvm.BaptismUrl,
                    BaptismCert         = dcvm.BaptismUrl,
                    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,
                    SODUrl              = dcvm.SODUrl,
                    SODCert             = dcvm.SODUrl,
                    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));
            }
        }