Exemplo n.º 1
0
        public ActionResult About()
        {
            var departmentleaders = _uow.Departments.GetAll();
            var dvm = new DeptViewModel
            {
                Departments = departmentleaders
            };

            return(View(dvm));;
        }
Exemplo n.º 2
0
        public ActionResult EditDept(int id)
        {
            var _dept = _uow.Departments.Get(id);
            var dvm   = new DeptViewModel
            {
                DeptLeaderName = _dept.DepartmentLeaderName,
                // DeptLeaderIamgeUrl=_dept.LeaderImageUrl,
                // DeptMeeting=_dept.MeetingDay,
                DeptLocation = _dept.Location,
                DeptName     = _dept.Name,
                Description  = _dept.Description,
                ImageUrl     = _dept.ImageUrl
            };

            return(View(dvm));
        }
Exemplo n.º 3
0
        public ActionResult AddDept(DeptViewModel dcvm)
        {
            if (ModelState.IsValid)
            {
                var existingdept = _uow.Departments.Find(t => t.Name == dcvm.DeptName.Trim()).FirstOrDefault();


                if (existingdept != null)
                {
                    ModelState.AddModelError("", $"A department with the name {dcvm.DeptName} already exists");
                    return(View(dcvm));
                }
                string fileName  = Path.GetFileNameWithoutExtension(dcvm.ImageFile.FileName);
                string extension = Path.GetExtension(dcvm.ImageFile.FileName);
                fileName      = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                dcvm.ImageUrl = fileName;
                fileName      = Path.Combine(Server.MapPath("~/Content/Images/"), fileName);
                dcvm.ImageFile.SaveAs(fileName);


                var dept = new Department
                {
                    Name                 = dcvm.DeptName,
                    Description          = dcvm.Description,
                    Location             = dcvm.DeptLocation,
                    ImageUrl             = dcvm.ImageUrl,
                    ImageThumbnailUrl    = dcvm.ImageUrl,
                    DepartmentLeaderName = dcvm.DeptLeaderName,
                };
                _uow.Departments.Add(dept);
                _uow.Commit();

                TempData["message"] = string.Format("{0} has been saved.", dcvm.DeptName);



                return(RedirectToAction("DepartmentList"));
            }
            else
            {
                return(View(dcvm));
            }
        }
Exemplo n.º 4
0
        public ActionResult EditDept(DeptViewModel dvm)
        {
            if (ModelState.IsValid)
            {
                var _depts = _uow.Departments.Get(dvm.Id);
                if (_depts != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(dvm.ImageFile.FileName);
                    string extension = Path.GetExtension(dvm.ImageFile.FileName);
                    fileName     = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    dvm.ImageUrl = fileName;
                    fileName     = Path.Combine(Server.MapPath("~/Content/Images/"), fileName);

                    _depts.Name        = dvm.DeptName;
                    _depts.Description = dvm.Description;
                    _depts.Location    = dvm.DeptLocation;
                    //_depts.MeetingDay = dvm.DeptMeeting;
                    _depts.ImageUrl             = dvm.ImageUrl;
                    _depts.ImageThumbnailUrl    = dvm.ImageUrl;
                    _depts.DepartmentLeaderName = dvm.DeptLeaderName;


                    if (dvm.ImageFile != null && dvm.ImageFile.ContentLength > 0)
                    {
                        dvm.ImageFile.SaveAs(fileName);
                    }
                    _uow.Commit();
                    TempData["message"] = $"{_depts.Name} was successfully edited.";
                }



                // _mailService.Send("A new department added", $"Department {dvm.DeptName}, and the Department Leader{dvm.DeptLeaderName} ");
                return(RedirectToAction("DepartmentList"));
            }
            else
            {
                return(View(dvm));
            }
        }