Пример #1
0
        protected void btnDelegate_Click(object sender, EventArgs e)
        {
            int           result;
            TemporaryRole newTemporaryRole = new TemporaryRole();

            newTemporaryRole.TemporaryRoleId = "ActHead";
            newTemporaryRole.EmployeeId      = Convert.ToInt32(hfSelectedEmployeeId.Value);

            DateTime StartDate, EndDate;

            if (!DateTime.TryParse(tbStartDate.Text, out StartDate) || !DateTime.TryParse(tbEndDate.Text, out EndDate))
            {
                result = 0;
            }
            else
            {
                newTemporaryRole.StartDate = StartDate;
                newTemporaryRole.EndDate   = EndDate;
            }

            result = authMgmt.CreateTemporaryAssignment(newTemporaryRole);

            if (result != 0)
            {
                PanelGoodMessage.Visible = true;
                lblGoodMessage.Text      = "The delegation of Acting Department Head is successful.";
                BindGrid();
            }
            else
            {
                PanelFailMessage.Visible = true;
                lblFailMessage.Text      = "The delegation of Acting Department Head is unsuccessful. Please try again.";
            }
        }
Пример #2
0
        public string AddAssignment(Assignment a)
        {
            string        result = "false";
            DateTime      StartDate, EndDate;
            string        format        = "dd-MM-yyyy";
            TemporaryRole temporaryRole = new TemporaryRole()
            {
                TemporaryRoleId = a.TemporaryRoleId,
                EmployeeId      = Convert.ToInt32(a.EmployeeId)
            };

            if (DateTime.TryParseExact(a.StartDate, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out StartDate) && DateTime.TryParseExact(a.EndDate, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out EndDate))
            {
                temporaryRole.StartDate = StartDate;
                temporaryRole.EndDate   = EndDate;
            }

            int outcome = tempRoleSer.CreateTemporaryRole(temporaryRole);

            if (outcome == 1)
            {
                result = "true";
            }
            return(result);
        }
Пример #3
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            int           result;
            int           actingHeadEmpId       = Convert.ToInt32(hfActingHeadEmployeeId.Value);
            TemporaryRole existingTemporaryRole = authMgmt.SearchAssignmentByEmpId(actingHeadEmpId);

            DateTime StartDate, EndDate;

            if (!DateTime.TryParse(tbStartDate.Text, out StartDate) || !DateTime.TryParse(tbEndDate.Text, out EndDate))
            {
                result = 0;
            }
            else
            {
                existingTemporaryRole.StartDate = StartDate;
                existingTemporaryRole.EndDate   = EndDate;
            }

            result = authMgmt.UpdateTemporaryAssignment(existingTemporaryRole);

            if (result > 0)
            {
                PanelGoodMessage.Visible = true;
                lblGoodMessage.Text      = "The delegation of Current Acting Department Head has been updated";
                BindGrid();
            }
            else
            {
                PanelFailMessage.Visible = true;
                lblFailMessage.Text      = "The update of delegation of Current Acting Department Head is unsuccessful. Please try again.";
            }
        }
 public int CreateAssignment(TemporaryRole temporaryRole)
 {
     try
     {
         ssae.TemporaryRoles.Add(temporaryRole);
         return(ssae.SaveChanges()); // returns 1
     }
     catch (Exception)
     {
         return(0); // 0 rows added
     }
 }
 public int DeleteAssignment(int empId)
 {
     try
     {
         TemporaryRole tr = ssae.TemporaryRoles.Where(x => x.EmployeeId == empId).FirstOrDefault();
         ssae.TemporaryRoles.Remove(tr);
         return(ssae.SaveChanges()); // returns 1
     }
     catch (Exception)
     {
         return(0); // 0 rows added
     }
 }
Пример #6
0
        public IActionResult GiveTemporaryRole(int userId,
                                               int roleId,
                                               int eventId)
        {
            List <string> errors = new List <string>();
            User          user   = Context.User.FirstOrDefault(f => f.Id == userId);
            Role          role   = Context.Role.FirstOrDefault(f => f.Id == roleId);
            Event         @event = Context.Event.FirstOrDefault(ff => ff.Id == eventId);

            if (role == null)
            {
                errors.Add("Role not found");
            }
            if (user == null)
            {
                errors.Add("User not found");
            }
            if (@event == null || [email protected]())
            {
                errors.Add("Event not found or expired");
            }

            if (errors.Count > 0)
            {
                return(NotFound(errors));
            }

            // Is already ann event ?
            if (Context.TemporaryRoles.Any(tt => tt.EventId == eventId &&
                                           tt.UserId == userId &&
                                           tt.RoleId == roleId))
            {
                return(BadRequest("User Already has this role"));
            }

            TemporaryRole temp = new TemporaryRole()
            {
                RoleId  = roleId,
                EventId = eventId,
                UserId  = userId
            };

            try {
                Context.TemporaryRoles.Add(temp);
                Context.SaveChanges();
            } catch (DbUpdateException e) {
                return(BadRequest(e.InnerException.Message));
            }

            return(Ok());
        }
Пример #7
0
        public bool IsActingHead(string userName)
        {
            int           empId         = SearchEmployeeByUserName(userName).EmployeeId;
            TemporaryRole temporaryRole = tempRoleSer.SearchTemporaryRoleByEmpId(empId);

            if (temporaryRole == null || DateTime.Compare(DateTime.Now.Date, temporaryRole.StartDate.Date) < 0 || DateTime.Compare(DateTime.Now.Date, temporaryRole.EndDate.Date) > 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
 public int UpdateAssignment(TemporaryRole temporaryRole)
 {
     try
     {
         TemporaryRole tr = ssae.TemporaryRoles.Where(x => x.EmployeeId == temporaryRole.EmployeeId).FirstOrDefault();
         tr.StartDate = temporaryRole.StartDate;
         tr.EndDate   = temporaryRole.EndDate;
         return(ssae.SaveChanges()); // returns 1
     }
     catch (Exception)
     {
         return(0); // 0 rows updated
     }
 }
Пример #9
0
        public IActionResult RemoveTempRole(int tempRoleId)
        {
            TemporaryRole temporary = Context.TemporaryRoles
                                      .FirstOrDefault((arg) => arg.Id == tempRoleId);

            if (temporary == null)
            {
                return(NotFound("Role not Found"));
            }

            try {
                Context.TemporaryRoles.Remove(temporary);
                Context.SaveChanges();
            } catch (DbUpdateException e) {
                return(BadRequest(e.InnerException.Message));
            }

            return(Ok());
        }
Пример #10
0
        private void BindGrid()
        {
            // Bind current acting director
            actingHead = authMgmt.SearchCurrentActingHead(deptId);
            if (actingHead != null)
            {
                temporaryRole                = authMgmt.SearchAssignmentByEmpId(actingHead.EmployeeId);
                tbEmpName.Text               = actingHead.EmployeeName;
                tbStartDate.Text             = temporaryRole.StartDate.ToString("yyyy-MM-dd");
                tbEndDate.Text               = temporaryRole.EndDate.ToString("yyyy-MM-dd");
                hfActingHeadEmployeeId.Value = actingHead.EmployeeId.ToString();
                btnRemove.Visible            = true;
                btnUpdate.Visible            = true;
                btnDelegate.Visible          = false;

                if (DateTime.Compare(DateTime.Now.Date, temporaryRole.StartDate.Date) > 0)
                {
                    tbStartDate.Enabled         = false;
                    tbEndDate.Attributes["min"] = DateTime.Now.ToString("yyyy-MM-dd");
                }
                else
                {
                    tbStartDate.Attributes["min"] = DateTime.Now.ToString("yyyy-MM-dd");
                    tbEndDate.Attributes["min"]   = DateTime.Now.ToString("yyyy-MM-dd");
                }
            }
            else
            {
                tbEmpName.Text               = "";
                tbStartDate.Text             = "";
                tbEndDate.Text               = "";
                hfActingHeadEmployeeId.Value = "";
                btnRemove.Visible            = false;
                btnUpdate.Visible            = false;
                btnDelegate.Visible          = true;

                tbStartDate.Enabled           = true;
                tbStartDate.Attributes["min"] = DateTime.Now.ToString("yyyy-MM-dd");
                tbEndDate.Attributes["min"]   = DateTime.Now.ToString("yyyy-MM-dd");
            }

            BindGridView();
        }
Пример #11
0
        public Assignment SearchAssignment(string deptId)
        {
            Assignment assignment = null;
            Employee   emp        = SearchCurrentActingHead(deptId);

            if (emp != null)
            {
                TemporaryRole temporaryRole = tempRoleSer.SearchTemporaryRoleByEmpId(emp.EmployeeId);
                if (temporaryRole != null)
                {
                    assignment = new Assignment()
                    {
                        EmployeeName    = emp.EmployeeName,
                        TemporaryRoleId = temporaryRole.TemporaryRoleId,
                        EmployeeId      = temporaryRole.EmployeeId.ToString(),
                        StartDate       = temporaryRole.StartDate.ToString("dd-MM-yyyy"),
                        EndDate         = temporaryRole.EndDate.ToString("dd-MM-yyyy")
                    };
                }
            }
            return(assignment);
        }
Пример #12
0
 public int CreateTemporaryRole(TemporaryRole temporaryRole)
 {
     return(tempRoleSer.CreateTemporaryRole(temporaryRole));
 }
Пример #13
0
 public int UpdateTemporaryRole(TemporaryRole temporaryRole)
 {
     return(tempRoleSer.UpdateTemporaryRole(temporaryRole));
 }
Пример #14
0
 public int CreateTemporaryAssignment(TemporaryRole temporaryRole)
 {
     return(tempRoleSer.CreateAssignment(temporaryRole));
 }