public List <Notification_Comm> GeCommListByNotificationId(string notifId) { if (String.IsNullOrEmpty(notifId)) { throw new ArgumentNullException("Parameter notifId cannot be null or empry!"); } List <Notification_Comm> lst = new List <Notification_Comm>(); DBContext.DBModel db = new DBContext.DBModel(); List <DBContext.Notification_Comunication_History> recordList = db.Notification_Comunication_History.Where(x => x.NotificationId == notifId).ToList(); if (recordList.Count > 0) { foreach (var record in recordList) { lst.Add(new Notification_Comm(record)); } } return(lst); }
//here we check that the number of items in tags list and in tagColors list to be fine //if they are the same we leave them //if there are less tags rather the colors, it is ok also //if there are more tags then colors, then we get the differece of tags from the params table private void checkForTagsAndColors() { int tagsCount = tags.Count(); int colorsCount = tagsColors.Count(); if (tagsCount > colorsCount) { int limit = tagsCount - colorsCount; DBContext.DBModel db = new DBContext.DBModel(); string defaultColors = db.Params.Where(x => x.Identifier == "Colors").Select(x => x.Param1).FirstOrDefault(); if (!String.IsNullOrEmpty(defaultColors)) { var colorList = defaultColors.Split(';'); int counter = 0; foreach (var color in colorList) { if (counter >= limit) { break; } if (!tagsColors.Contains(color)) { tagsColors.Add(color); } counter++; } } } }
public static void UpdateStatus(DBContext.PartialTime_Requests rec, string newStatus) { if (rec == null) { throw new ArgumentNullException("Record from Db cannot be null"); } if (String.IsNullOrEmpty(newStatus)) { throw new ArgumentNullException("Status Argument cannot be null or Empty"); } var db = new DBContext.DBModel(); rec.Status = newStatus; try { db.PartialTime_Requests.Attach(rec); db.SaveChanges(); } catch (Exception ex) { //log the error; throw ex; } }
public void AddNewRecord(Notification_Comm notifMessage) { if (notifMessage == null) { throw new ArgumentNullException("Parameter supplied cannot be null!"); } DBContext.DBModel db = new DBContext.DBModel(); DBContext.Notification_Comunication_History message = new DBContext.Notification_Comunication_History { NotificationId = notifMessage.NotificationID, Message = notifMessage.Message, UpdatedDate = notifMessage.UpdatedDate, SubmitedBy = notifMessage.SubmitedBy }; try { db.Notification_Comunication_History.Add(message); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
private int InsertRecord(DBContext.Main_Data record) { DBContext.DBModel db = new DBContext.DBModel(); db.Main_Data.Add(record); db.SaveChanges(); int id = (int)record.ID; return(id); }
private void GetUserSettings() { DBContext.DBModel db = new DBContext.DBModel(); var settings = db.User_Settings.Find(User.ID); if (settings != null) { UserSettings = new UserSettings(settings); } }
private void getProjectNameFromId() { DBContext.DBModel db = new DBContext.DBModel(); var projectName = db.User_Assigned_Projects.Where(x => x.ProjectId == this.projectId).Select(x => x.ProjectName).FirstOrDefault(); if (string.IsNullOrEmpty(projectName)) { throw new ArgumentException("You are not assign to the project!"); } this.projectName = projectName; }
private string getProjectName(int projectId) { string projectName = ""; DBContext.DBModel db = new DBContext.DBModel(); projectName = db.Projects.Where(x => x.Id == projectId).Select(x => x.Name).FirstOrDefault(); if (projectName == null) { projectName = "Other"; } return(projectName); }
public static void AddRecord(DBContext.PartialTime_Requests rec) { if (rec == null) { throw new ArgumentNullException("Argument cannot be null."); } var db = new DBContext.DBModel(); try { db.PartialTime_Requests.Add(rec); db.SaveChanges(); } catch (Exception ex) { //log error throw ex; } }
public static void InsertNotification(string userId, DateTime receiveDate, string title, string message, string sender, string type) { var db = new DBContext.DBModel(); var record = new DBContext.LiveNotification(); record.UserId = userId; record.DateReceived = receiveDate; record.Title = title; record.Message = message; record.Sender = sender; record.Type = type; try { db.LiveNotifications.Add(record); db.SaveChanges(); } catch (Exception ex) { throw ex; } }
private Dictionary <string, string> CheckTaskForPotentialIssues(Models.Portal.WorkRecord task, Models.Security.User user) { Dictionary <string, string> issues = new Dictionary <string, string>(); DBContext.DBModel db = new DBContext.DBModel(); if (user == null) { user = GetUserFromSession(); } if (task == null) { issues.Add("Missing Data", "The Task was not submited successfully"); } else { //Check that the start time should not be grater then the end time if (task.startDate > task.endDate) { issues.Add("Invalid Time", "Start time cannot be higher then end time!"); } //Check if it is Sunday or Saturday if (task.currentDate.DayOfWeek == DayOfWeek.Saturday || task.currentDate.DayOfWeek == DayOfWeek.Sunday) { issues.Add("Wrong Day", "Cannot add task on: " + task.currentDate.DayOfWeek); } //check if it is bank holiday var isBankHoliday = db.Public_Holidays.Where(x => x.Holiday_date == task.currentDate.Date).FirstOrDefault(); if (isBankHoliday != null) { issues.Add("Bank Holiday", "On: " + task.currentDate.ToString("dd/MM/yyyy") + " is Public Holyday: " + isBankHoliday.Holiday_name); } //check if it is on leave already var leaves = db.Leaves.Where(x => x.StartDate <= task.currentDate.Date && x.EndDate >= task.currentDate.Date).FirstOrDefault(); if (leaves != null) { issues.Add("Leave", "Cannot add Task on Leave Day!"); } var requestedLeaves = db.Leave_Requests.Where(x => x.RequestStartDate <= task.currentDate.Date && x.RequestEndDate >= task.currentDate.Date).FirstOrDefault(); if (requestedLeaves != null) { issues.Add("Requested Leave", "Leave requested for the day!"); } //get a list of records for the task day. var taskDate = task.currentDate.Date; var existingRecords = db.Main_Data.Where(x => x.CurrentDate.Day == taskDate.Day && x.CurrentDate.Month == taskDate.Month && x.CurrentDate.Year == taskDate.Year && x.User_ID == user.ID).ToList(); var overlapingRecord = existingRecords.Where(x => x.Status_Start_Time <= task.startDate && x.Status_End_Time >= task.startDate).FirstOrDefault(); if (overlapingRecord != null) { issues.Add("Wrong Start Time", "Interval already existing with Title: " + overlapingRecord.Title); } overlapingRecord = db.Main_Data.Where(x => x.Status_Start_Time <= task.endDate && x.Status_Start_Time >= task.startDate).FirstOrDefault(); if (overlapingRecord != null) { issues.Add("Wrong End Time", "Interval already existing with Title: " + overlapingRecord.Title); } } return(issues); }
private static List <Alert> checkForDaysThatAreNotUpdated() { var db = new DBContext.DBModel(); List <Alert> alerts = new List <Alert>(); //get the list of dates when the user has not submited worklogs or is not on leave; DateTime today = DateTime.UtcNow.Date; const int daysToCheck = -30; //we need to check for the past 30 days the user and see if it has updated the worklog or is on leave; DateTime start = today.AddDays(daysToCheck).Date; List <DateTime> listOfDatestoCheck = new List <DateTime>(); //list of dates that needs to be checked for (int i = daysToCheck; i < 0; i++) { if (today.AddDays(i).DayOfWeek != DayOfWeek.Sunday && today.AddDays(i).DayOfWeek != DayOfWeek.Saturday)// exclude sunday and saturday { listOfDatestoCheck.Add(today.AddDays(i).Date); } } //first get a list of days on which the user has not updated the worklog var listOfUpdatedDates = db.Main_Data.Where(x => x.Status_Start_Time >= start && x.Status_Start_Time < today.Date && x.User_ID == User.ID).Select(x => x.Status_Start_Time).Distinct().ToList(); //list of the dates where the user made an update var filteredList = listOfUpdatedDates.Select(x => x.Date).ToList(); filteredList = filteredList.Distinct().ToList(); //if the 2 lists have the same number of elements, means that the user has already updated all the days if (listOfDatestoCheck.Count == filteredList.Count) { return(alerts); } //check if there are any leaves in that timeframe var leaves = db.Leaves.Where(x => x.UserId == User.ID && ((x.StartDate.Value >= start.Date && x.StartDate.Value < today.Date) || (x.StartDate.Value <start.Date && x.EndDate.Value> start.Date))).ToList(); List <DateTime> leaveDays = new List <DateTime>();// list of the actual leave days; if (leaves.Count > 0) { foreach (var leave in leaves) { var days = (leave.EndDate.Value - leave.StartDate.Value).Days; //get he number of days that exists in the vacation //get the actual days that are in the leave; var startD = leave.StartDate.Value.Date; for (var i = days; i > 0; i--) { leaveDays.Add(startD.AddDays(i).Date); } } } //remove any date that is in the leave list foreach (var leave in leaveDays) { if (listOfDatestoCheck.Contains(leave)) { listOfDatestoCheck.Remove(leave); } } //now actually remains all other dates //check the remaining list against the one we extracted //after removing the leaves, check again to see if the list matches with the one already extracted; if (listOfDatestoCheck.Count == filteredList.Count) { return(alerts); } //get the pending leave? or leave it as alert? //check for any bank holidays var bankHolidays = db.Public_Holidays.Where(x => x.Holiday_country == User.Country && (x.Holiday_date.Value > start.Date && x.Holiday_date.Value < today.Date)).ToList(); foreach (var bh in bankHolidays) { if (listOfDatestoCheck.Contains(bh.Holiday_date.Value.Date)) { listOfDatestoCheck.Remove(bh.Holiday_date.Value.Date); } } foreach (var workday in filteredList) { if (listOfDatestoCheck.Contains(workday.Date)) { listOfDatestoCheck.Remove(workday); } } //now after removing the actual posted dates, we should remain with the dates that are actually not updated //return the list string message = "You appear to be absent on the following dates: <strong>"; string datesFormated = ""; if (listOfDatestoCheck.Count > 0) { foreach (var item in listOfDatestoCheck) { datesFormated += item.Date.ToString("dd MMM yyyy") + "; "; } datesFormated = datesFormated.Remove(datesFormated.Length - 2, 2); } //message = message.Remove(message.Length - 3, 2); message += datesFormated + "</strong>"; message += " . Please go and update the records accordingly!"; alerts.Add(CreateMissingDay(message, true, true)); return(alerts); }