public static void Save(LeaveTypeModel _leaveType, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { if (_leaveType.ID == null || _leaveType.ID == Guid.Empty) { LeaveType newLeaveType = new LeaveType { ID = Guid.NewGuid(), Description = _leaveType.Description, CreatedBy = UniversalHelpers.CurrentUser.ID, CreatedDate = DateTime.Now, DaysBeforeFilling = _leaveType.DaysBeforeFilling, Type = _leaveType.Type, LeaveDeduction = _leaveType.LeaveDeduction }; db.Entry(newLeaveType).State = EntityState.Added; } else //Update { var leave = db.LeaveType.FirstOrDefault(r => r.ID == _leaveType.ID); if (leave != null) { if (_leaveType.Status == "X") { db.Entry(leave).State = EntityState.Deleted; } else { leave.Description = _leaveType.Description; leave.CreatedBy = UniversalHelpers.CurrentUser.ID; leave.CreatedDate = DateTime.Now; leave.DaysBeforeFilling = _leaveType.DaysBeforeFilling; leave.Type = _leaveType.Type; leave.LeaveDeduction = _leaveType.LeaveDeduction; db.Entry(leave).State = EntityState.Modified; } } } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }
public static void Save(CalendarModel model, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { if (model.ID == null || model.ID == Guid.Empty) { Holiday newHoliday = new Holiday { ID = Guid.NewGuid(), Description = model.title, StartDate = model.end, EndDate = model.start, CreatedBy = UniversalHelpers.CurrentUser.ID, CreatedDate = DateTime.Now }; db.Entry(newHoliday).State = EntityState.Added; } else { var holiday = db.Holiday.FirstOrDefault(r => r.ID == model.ID); if (holiday != null) { if (model.Status == "X") { db.Entry(holiday).State = EntityState.Deleted; } else { holiday.Description = model.title; holiday.EndDate = model.end; holiday.StartDate = model.start; holiday.CreatedBy = UniversalHelpers.CurrentUser.ID; holiday.CreatedDate = DateTime.Now; db.Entry(holiday).State = EntityState.Modified; } } } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }
public static void SaveMember(GroupApproverMemberModel _member, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { if (_member.ID == Guid.Empty || _member.ID == null)//NEW { var ifExist = db.ApproverGroupMember.FirstOrDefault(r => r.UserID == _member.UserID); if (ifExist == null) { ApproverGroupMember newMember = new ApproverGroupMember { ID = Guid.NewGuid(), GroupID = _member.GroupID, UserID = _member.UserID }; db.Entry(newMember).State = EntityState.Added; } else { message = "Employee is already a member"; } } else //UPDATE { var member = db.ApproverGroupMember.FirstOrDefault(r => r.ID == _member.ID); if (member != null) { if (_member.Status == "X") { db.Entry(member).State = EntityState.Deleted; } } } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }
public static void Save(AdvisoryModel _advisory, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { if (_advisory.ID == Guid.Empty) { Advisory newAdvisory = new Advisory { ID = Guid.NewGuid(), Description = _advisory.Description, ModifiedBy = UniversalHelpers.CurrentUser.ID, ModifiedDate = DateTime.Now }; db.Entry(newAdvisory).State = System.Data.Entity.EntityState.Added; } else { var adv = db.Advisory.FirstOrDefault(r => r.ID == _advisory.ID); if (adv != null && _advisory.Status == 1) { adv.Description = _advisory.Description; adv.ModifiedBy = UniversalHelpers.CurrentUser.ID; adv.ModifiedDate = DateTime.Now; db.Entry(adv).State = System.Data.Entity.EntityState.Modified; } else if (_advisory.Status == 0) { db.Entry(adv).State = System.Data.Entity.EntityState.Deleted; } } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }
public static void AddCreditPerEmployee(Guid _userID, int VL, int SL, int soloLeave, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { var user = db.UserAccount.FirstOrDefault(r => r.ID == _userID); if (user != null) { user.VacationLeavCount += VL; user.SickLeaveCount += SL; user.SoloParentLeaveCount += soloLeave; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } } } catch (Exception error) { message = error.Message; } }
public static void AddCreditPerGroup(Guid _groupID, int VL, int SL, int soloLeave, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { var users = db.UserAccount.Where(r => r.DeptID == _groupID).ToList(); if (users != null) { users.ToList().ForEach(user => { user.VacationLeavCount += VL; user.SickLeaveCount += SL; user.SoloParentLeaveCount += soloLeave; db.Entry(user).State = EntityState.Modified; }); db.SaveChanges(); } } } catch (Exception error) { message = error.Message; } }
public static void ChangePassword(string _oldPassword, string _newPassword, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { var user = db.UserAccount.FirstOrDefault(r => r.ID == UniversalHelpers.CurrentUser.ID && r.Password == _oldPassword); if (user != null) { user.Password = _newPassword; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); } else { message = "Invalid Password. . ."; } } } catch (Exception error) { message = error.Message; } }
public static void SaveEmail(EmailAccountModel _email, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { var email = db.EmailCredential.FirstOrDefault(r => r.ID != null); if (email == null) { EmailCredential newEmail = new EmailCredential { ID = Guid.NewGuid(), Email = _email.Email, Password = _email.Password }; db.Entry(newEmail).State = EntityState.Added; } else { _email.Password = _email.Password; _email.Email = _email.Email; db.Entry(_email).State = EntityState.Modified; } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }
public static void SaveUpdate(OvertimeFormModel _overtime, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { if (_overtime.ID == Guid.Empty || _overtime.ID == null) { OvertimeForm newOvertime = new OvertimeForm { ID = Guid.NewGuid(), EffectiveDate = _overtime.EffectiveDate, StartTime = _overtime.StartTime, EndTime = _overtime.EndTime, CreatedBy = UniversalHelpers.CurrentUser.ID, CreatedDate = DateTime.Now, Reason = _overtime.Reason, Status = "P" }; db.Entry(newOvertime).State = EntityState.Added; //========FIRST APPROVER EMAIL============== EmailService.SendEmail("Overtime For Approval", UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName + " filed overtime and waiting for your approval", UniversalHelpers.CurrentUser.FirstApproverEmail); //========SECOND APPROVER EMAIL============= EmailService.SendEmail("Overtime For Approval", UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName + " filed overtime and waiting for your approval", UniversalHelpers.CurrentUser.SecondApproverEmail); } else { var ot = db.OvertimeForm.FirstOrDefault(r => r.ID == _overtime.ID); if (ot != null) { var user = db.UserAccount.FirstOrDefault(r => r.ID == ot.CreatedBy); ot.Status = _overtime.Status; if (_overtime.Status == "D") { EmailService.SendEmail("Filed Overtime Declined", "Your filed overtime has been declined by " + UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName, user.Email); } else if (_overtime.Status == "A") { EmailService.SendEmail("Filed Overtime Approved", "Your filed overtime has been approved by " + UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName, user.Email); } else if (_overtime.Status == "X") { EmailService.SendEmail("Filed Overtime of " + UniversalHelpers.CurrentUser.FirstName + " has been canceled", "Filed overtime of " + UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName + " has been canceled for some reasons", UniversalHelpers.CurrentUser.FirstApproverEmail); EmailService.SendEmail("Filed Overtime of " + UniversalHelpers.CurrentUser.FirstName + " has been canceled", "Filed overtime of " + UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName + " has been canceled for some reasons", UniversalHelpers.CurrentUser.SecondApproverEmail); } db.Entry(ot).State = EntityState.Modified; } } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }
public static void SaveUpdate(LeaveFormModel _leave, out string message) { try { message = ""; var leaveDays = _leave.EndDate.Subtract(_leave.StartDate).TotalDays + 1; using (var db = new SLVLOnlineEntities()) { if (_leave.ID == Guid.Empty || _leave.ID == null) { var leaveType = db.LeaveType.FirstOrDefault(r => r.ID == _leave.Type); if (leaveType.Type == "SL") { if (UniversalHelpers.CurrentUser.SickLeaveCount < (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString()))) { message = "Insufficient Sick Leave Credit"; } } else if (leaveType.Type == "VL" || leaveType.Type == "EL") { if (UniversalHelpers.CurrentUser.VacationLeaveCount < (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString()))) { message = "Insufficient Vacation Leave Credit"; } } else if (leaveType.Type == "PL") { if (UniversalHelpers.CurrentUser.SoloParentLeaveCount < (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString()))) { message = "Insufficient Solo Parent Leave Credit"; } } LeaveForm newLeave = new LeaveForm { ID = Guid.NewGuid(), CreatedBy = UniversalHelpers.CurrentUser.ID, CreatedDate = DateTime.Now, EndDate = _leave.EndDate, Reason = _leave.Reason, StartDate = _leave.StartDate, Status = "P", Type = _leave.Type }; db.Entry(newLeave).State = EntityState.Added; db.SaveChanges(); //========FIRST APPROVER EMAIL============== EmailService.SendEmail("Leave For Approval", UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName + " filed " + _leave.ShowType + " and waiting for your approval", UniversalHelpers.CurrentUser.FirstApproverEmail); //========SECOND APPROVER EMAIL============= EmailService.SendEmail("Leave For Approval", UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName + " filed " + _leave.ShowType + " and waiting for your approval", UniversalHelpers.CurrentUser.SecondApproverEmail); } else { leaveDays = DateTime.Parse(_leave.ShowEndDate).Subtract(DateTime.Parse(_leave.ShowStartDate)).TotalDays + 1; var leave = db.LeaveForm.FirstOrDefault(r => r.ID == _leave.ID); var leaveType = db.LeaveType.FirstOrDefault(r => r.ID == _leave.Type); if (leave != null) { var user = db.UserAccount.FirstOrDefault(r => r.ID == leave.CreatedBy); if (_leave.Status == "D") { EmailService.SendEmail("Filed Leave Declined", "Your filed Leave has been declined by " + UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName, user.Email); } else if (_leave.Status == "A") { EmailService.SendEmail("Filed Leave Approved", "Your filed Leave has been approved by " + UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName, user.Email); if (leaveType.Type == "SL") { user.SickLeaveCount = user.SickLeaveCount - (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString())); } else if (leaveType.Type == "VL" || leaveType.Type == "EL") { user.VacationLeavCount = user.VacationLeavCount - (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString())); } else if (leaveType.Type == "PL") { user.SoloParentLeaveCount = user.SoloParentLeaveCount - (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString())); } } else if (_leave.Status == "X") { EmailService.SendEmail("Filed Leave of " + UniversalHelpers.CurrentUser.FirstName + " has been canceled", "Filed Leave of " + UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName + " has been canceled for some reasons", UniversalHelpers.CurrentUser.FirstApproverEmail); EmailService.SendEmail("Filed Leave of " + UniversalHelpers.CurrentUser.FirstName + " has been canceled", "Filed Leave of " + UniversalHelpers.CurrentUser.FirstName + " " + UniversalHelpers.CurrentUser.LastName + " has been canceled for some reasons", UniversalHelpers.CurrentUser.SecondApproverEmail); if (leave.Status == "A") { if (leaveType.Type == "SL") { user.SickLeaveCount = user.SickLeaveCount + (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString())); } else if (leaveType.Type == "VL" || leaveType.Type == "EL") { user.VacationLeavCount = user.VacationLeavCount + (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString())); } else if (leaveType.Type == "PL") { user.SoloParentLeaveCount = user.SoloParentLeaveCount + (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString())); } } } leave.Status = _leave.Status; leave.DeclineReason = _leave.DeclineReason; db.Entry(leave).State = EntityState.Modified; db.SaveChanges(); } } } } catch (Exception error) { message = error.Message; } }
public static void SaveUpdateAdmin(LeaveFormModel _leave, UserModel _user, out string message) { try { message = ""; var leaveDays = _leave.EndDate.Subtract(_leave.StartDate).TotalDays + 1; using (var db = new SLVLOnlineEntities()) { if (_leave.ID == Guid.Empty || _leave.ID == null) { var leaveType = db.LeaveType.FirstOrDefault(r => r.ID == _leave.Type); if (leaveType.Type == "SL") { if (_user.SickLeaveCount < (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString()))) { message = "Insufficient Sick Leave Credit"; } } else if (leaveType.Type == "VL" || leaveType.Type == "EL") { if (_user.VacationLeaveCount < (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString()))) { message = "Insufficient Vacation Leave Credit"; } } else if (leaveType.Type == "PL") { if (_user.SoloParentLeaveCount < (leaveDays * double.Parse(leaveType.LeaveDeduction.ToString()))) { message = "Insufficient Solo Parent Leave Credit"; } } Guid?CreatedBy = Guid.Empty; if (_leave.FileForUser == null || _leave.FileForUser == Guid.Empty) { CreatedBy = UniversalHelpers.CurrentUser.ID; } else { CreatedBy = _leave.FileForUser; } LeaveForm newLeave = new LeaveForm { ID = Guid.NewGuid(), CreatedBy = CreatedBy, CreatedDate = DateTime.Now, EndDate = _leave.EndDate, Reason = _leave.Reason, StartDate = _leave.StartDate, Status = "P", Type = _leave.Type }; db.Entry(newLeave).State = EntityState.Added; db.SaveChanges(); //========FIRST APPROVER EMAIL============== EmailService.SendEmail("Leave For Approval", _user.FirstName + " " + _user.LastName + " filed " + _leave.ShowType + " and waiting for your approval", _user.FirstApproverEmail); //========SECOND APPROVER EMAIL============= EmailService.SendEmail("Leave For Approval", _user.FirstName + " " + _user.LastName + " filed " + _leave.ShowType + " and waiting for your approval", _user.SecondApproverEmail); } } } catch (Exception error) { message = error.Message; } }
public static void SaveGroup(GroupApproverModel _group, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { if (_group.ID == Guid.Empty || _group.ID == null) //NEW { ApproverGroup newGroup = new ApproverGroup { ID = Guid.NewGuid(), Name = _group.Name, FirstApprover = _group.FirstApprover, SecondApprover = _group.SecondApprover }; db.Entry(newGroup).State = EntityState.Added; } else //UPDATE { var group = db.ApproverGroup.FirstOrDefault(r => r.ID == _group.ID); if (group != null) { if (_group.Status == "X") { db.Entry(group).State = EntityState.Deleted; var members = db.ApproverGroupMember.Where(r => r.GroupID == _group.ID); if (members != null) { members.ToList().ForEach(item => { db.Entry(item).State = EntityState.Deleted; }); } } else { group.Name = _group.Name; group.FirstApprover = _group.FirstApprover; group.SecondApprover = _group.SecondApprover; db.Entry(group).State = EntityState.Modified; } } } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }
public static void Save(UserModel _user, out string message) { try { message = ""; using (var db = new SLVLOnlineEntities()) { if (_user.ID == Guid.Empty || _user.ID == null)//NEW { UserAccount newUser = new UserAccount { ID = Guid.NewGuid(), Status = "Y", Username = _user.Username, Password = _user.Password, FirstName = _user.FirstName, MiddleInitial = _user.MiddleInitial, LastName = _user.LastName, Birthdate = _user.BirthDate, Gender = _user.Gender, CivilStatus = _user.CivilStatus, BirthPlace = _user.BirthPlace, Position = _user.Position, DateHired = _user.DateHired, ContactNo = _user.ContactNo, Email = _user.Email, Type = _user.Type, DeptID = _user.DeptID, SoloParentLeaveCount = _user.SoloParentLeaveCount, SickLeaveCount = _user.SickLeaveCount, VacationLeavCount = _user.VacationLeaveCount }; db.Entry(newUser).State = EntityState.Added; } else //Update { var user = db.UserAccount.FirstOrDefault(r => r.ID == _user.ID); user.Username = _user.Username; user.FirstName = _user.FirstName; user.MiddleInitial = _user.MiddleInitial; user.LastName = _user.LastName; user.Status = _user.Status; user.Birthdate = _user.BirthDate; user.Gender = _user.Gender; user.CivilStatus = _user.CivilStatus; user.BirthPlace = _user.BirthPlace; user.Position = _user.Position; user.DateHired = _user.DateHired; user.ContactNo = _user.ContactNo; user.Email = _user.Email; user.Type = _user.Type; user.DeptID = _user.DeptID; user.VacationLeavCount = _user.VacationLeaveCount; user.SickLeaveCount = _user.SickLeaveCount; user.SoloParentLeaveCount = user.SoloParentLeaveCount; if (_user.Password != null && _user.Password != "") { user.Password = _user.Password; } db.Entry(user).State = EntityState.Modified; } db.SaveChanges(); } } catch (Exception error) { message = error.Message; } }