예제 #1
0
        public ActionResult AssignReportManager(reportmanagerViewModel model)
        {
            ReportManagers manager = new ReportManagers();
            //var existingManager = ReportRepo.GetReportManagerById(model.userId);
            var existingManager = employeeManager.DoesReportManagerExist(model.userId, int.Parse(model.BunitId));

            if (ModelState.IsValid && existingManager == false)
            {
                manager.BusinessUnitId = int.Parse(model.BunitId);
                manager.managerId      = model.userId;
                var employee = employeeManager.CheckIfEmployeeExistByUserId(model.userId);
                if (employee != false)
                {
                    var result = empRepo.GetEmployeeByUserid(model.userId);
                    manager.employeeId   = result.empID;
                    manager.DepartmentId = result.departmentId;
                    manager.FullName     = result.FullName;
                    result.IsUnithead    = true;
                    result.empRoleId     = 2;
                    empRepo.UpdateEmployees(result);                                        //fix this later by making this update the employee table
                    var resultRole = userManager.RemoveFromRole(result.userId, "Employee"); //Fix this later and make sure the adding and removing is workin well.
                    if (resultRole.Succeeded)
                    {
                        userManager.AddToRole(result.userId, "Manager");
                        ReportRepo.AddReportMananger(manager);
                    }
                    return(RedirectToAction("allEmployee"));
                }
                else
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
                }
            }
            else
            {
                ViewBag.businessUnits = new SelectList(BunitsRepo.GetBusinessUnit().OrderBy(x => x.BusId), "BusId", "unitname", "BusId");
                TempData["Error"]     = "Make sure that the report Manager does not exist already for the business unit";
                TempData["Warning"]   = "Also make sure thatyou don't add an employee twice for particlar business unit";
                return(View());
            }
        }
예제 #2
0
 public void AddReportMananger(ReportManagers manager)
 {
     unitOfWork.ReportManager.Insert(manager);
     unitOfWork.Save();
 }