//cancel delegation public static DelegationModel CancelDelegation(DelegationModel dm, out String error) { error = ""; // declare and initialize new LUSSISEntities to perform update LUSSISEntities entities = new LUSSISEntities(); delegation d = new delegation(); try { // finding the delegation object using delegation API model d = entities.delegations.Where(p => p.delid == dm.Delid).First <delegation>(); d.active = ConDelegation.Active.INACTIVE; // saving the update entities.SaveChanges(); UserRepo.Canceldelegateuser(dm.Userid); // return the updated model dm = GetDelegationByDelegationID(d.delid, out error); user us = entities.users.Where(p => p.userid == dm.Userid).FirstOrDefault(); NotificationModel nom = new NotificationModel(); nom.Deptid = us.deptid; nom.Role = ConUser.Role.EMPLOYEEREP; nom.Title = "Authority Cancellation"; nom.NotiType = ConNotification.NotiType.DelegationAssigned; nom.ResID = dm.Userid; nom.Remark = us.fullname + " has been removed as a Temp Head of Department!"; nom = NotificationRepo.CreatNotification(nom, out error); nom.Deptid = us.deptid; nom.Role = ConUser.Role.TEMPHOD; nom.Title = "Authority Cancellation"; nom.NotiType = ConNotification.NotiType.DelegationAssigned; nom.ResID = dm.Userid; nom.Remark = us.fullname + " has been removed as a Temp Head of Department!"; nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(dm); }
//create delegation public static DelegationModel CreateDelegation(DelegationModel dele, out string error) { error = ""; LUSSISEntities entities = new LUSSISEntities(); delegation d = new delegation(); DelegationModel ndel = new DelegationModel(); try { DepartmentModel dep = DepartmentRepo.GetDepartmentByUserid(dele.Userid, out error); List <UserModel> userlist = UserRepo.GetUserByDeptid(dep.Deptid, out error); foreach (UserModel u in userlist) { List <DelegationModel> delelist = GetDelegationByUserId(u.Userid, out error); foreach (DelegationModel deleg in delelist) { delegation del = entities.delegations.Where(p => p.delid == deleg.Delid).FirstOrDefault <delegation>(); del.active = ConDelegation.Active.INACTIVE; if (u.Role != ConUser.Role.DEPARTMENTREP) { UserRepo.Canceldelegateuser(u.Userid); } entities.SaveChanges(); } } d.startdate = dele.Startdate; d.enddate = dele.Enddate; d.userid = dele.Userid; d.active = ConDelegation.Active.ACTIVE; d.assignedby = dele.AssignedbyId; d = entities.delegations.Add(d); entities.SaveChanges(); dele = GetDelegationByDelegationID(d.delid, out error); user us = entities.users.Where(p => p.userid == dele.Userid).FirstOrDefault(); NotificationModel nom = new NotificationModel(); nom.Deptid = us.deptid; nom.Role = ConUser.Role.TEMPHOD; nom.Title = "New Authority"; nom.NotiType = ConNotification.NotiType.DelegationAssigned; nom.ResID = dele.Userid; nom.Remark = us.fullname + " has been assigned as a Temp HOD from " + dele.Startdate.Value.ToShortDateString() + " to " + dele.Enddate.Value.ToShortDateString(); nom = NotificationRepo.CreatNotification(nom, out error); nom.Deptid = us.deptid; nom.Role = ConUser.Role.EMPLOYEEREP; nom.Title = "New Authority"; nom.NotiType = ConNotification.NotiType.DelegationAssigned; nom.ResID = dele.Userid; nom.Remark = us.fullname + " has been assigned as a Temp HOD from " + dele.Startdate.Value.ToShortDateString() + " to " + dele.Enddate.Value.ToShortDateString(); nom = NotificationRepo.CreatNotification(nom, out error); } catch (NullReferenceException) { error = ConError.Status.NOTFOUND; } catch (Exception e) { error = e.Message; } return(dele); }