public JsonResult TimesheetApprove(string[] DATA) { try { foreach (var i in DATA) { var res = JsonConvert.DeserializeObject <ActionItemList>(i); var sequenceNubmer = DB.EmpTimeSheet.Find(res.TsID).SequenceNo; var records = DB.EmpTimeSheet.Where(x => x.SequenceNo == sequenceNubmer).ToList(); foreach (var existing in records) { if (existing != null) { // existing.InvolvePercent = 0; existing.Status = Convert.ToInt64(ReadConfig.GetValue("StatusApproved")); existing.ApproveRejectComments = ""; existing.ApproveRejectStatus = "A"; existing.ApproveRejectUser = (Int64)Session[Constants.SessionEmpID]; existing.ApproveRejectDate = DateTime.Now; DB.EmpTimeSheet.Attach(existing); DB.Entry(existing).State = System.Data.Entity.EntityState.Modified; } } DB.SaveChanges(); } } catch (Exception ex) { TempData["Error"] = ex.ToString(); LogHelper.ErrorLog(ex); } return(Json(new { data = true })); }
public JsonResult TimesheetReject(string[] DATA) { try { foreach (string i in DATA) { ActionItems res = JsonConvert.DeserializeObject <ActionItems>(i); NewEntryModel existing = DB.EmpTimeSheet.Find(res.TsID); if (existing != null) { existing.Status = Convert.ToInt64(ReadConfig.GetValue("StatusRejected")); existing.ApproveRejectComments = ""; existing.ApproveRejectStatus = "R"; existing.ApproveRejectUser = (long)Session[Constants.SessionEmpID]; existing.ApproveRejectDate = DateTime.Now; DB.EmpTimeSheet.Attach(existing); DB.Entry(existing).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } } catch (Exception ex) { TempData["Error"] = ex.ToString(); LogHelper.ErrorLog(ex); } return(Json(new { data = true })); }
public static IEnumerable <MasterLookUp> GrantList(long?empId = null) { ApplicationDBContext DB = new ApplicationDBContext(); try { if (empId.HasValue) { long grantId = Convert.ToInt64(ReadConfig.GetValue("TypeGrant")); DateTime lastDayOfMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)); IEnumerable <MasterLookUp> Grants = (from x in DB.MasterData join z in DB.ProjectMaster on x.MstID equals z.ProjectGrant join y in DB.ProjectEmployee on z.ProjectID equals y.ProjectID where y.EmployeeID == empId.Value select new MasterLookUp { MstID = x.MstID, MstCode = x.MstCode + "-" + x.MstName }).Distinct().ToList(); return(Grants); } else { IEnumerable <MasterLookUp> Grants = DB.MasterData.AsEnumerable().Where(x => x.MstTypeID == Convert.ToInt64(ReadConfig.GetValue("TypeGrant"))).Select(x => new MasterLookUp { MstID = x.MstID, MstCode = x.MstCode + "-" + x.MstName }).ToList(); return(Grants); } } catch (Exception ex) { LogHelper.ErrorLog(ex); throw ex; } }
public static async Task <bool> SendTimeSubmissionEmail(TimeSheetSubmissionEmailModel emailModel) { if (DB == null) { DB = new ApplicationDBContext(); } bool result = false; try { var templateCode = ConfigurationManager.AppSettings["TSEmailTemplateCode"].ToString(); SCTimeSheet_DAL.Models.EmailTemplates emailTemplate = DB.EmailTemplates.FirstOrDefault(x => x.EmailTemplateCode == templateCode); if (emailTemplate != null) { MailMessage mail = new MailMessage(); foreach (var item in emailModel.ManagerInfo) { mail.To.Add(new MailAddress(item.Email)); } string _mailId = ReadConfig.GetValue("SystemEmail"); string _mailPassword = ReadConfig.GetValue("MailPassword"); int _mailPort = Convert.ToInt32(ReadConfig.GetValue("MailPort")); string _mailHost = ReadConfig.GetValue("MailHost"); bool _enableSsl = Convert.ToBoolean(ReadConfig.GetValue("EnableSsl")); mail.From = new MailAddress(_mailId); mail.CC.Add(new MailAddress(_mailId)); mail.Subject = emailTemplate.EmailSubject; string Body = string.Format(emailTemplate.EmailBody, string.Join("/", emailModel.ManagerInfo.Select(x => Models.Common.GetName(x.EmpFirstName, x.EmpLastName, x.EmpMiddleName))), emailModel.EmpName, emailModel.SubmissionDates, emailModel.ProjectName); mail.Body = Body; mail.IsBodyHtml = true; using (SmtpClient smtp = new SmtpClient()) { NetworkCredential credential = new NetworkCredential { UserName = _mailId, Password = _mailPassword }; smtp.Credentials = credential; smtp.Host = _mailHost; smtp.Port = _mailPort; smtp.EnableSsl = _enableSsl; await smtp.SendMailAsync(mail); } result = true; } else { throw new Exception("Time Sheet Submission Email Template not found"); } } catch (Exception ex) { LogHelper.ErrorLog(ex); return(result); } return(result); }
public ActionResult SingleApprove(PendingListforApproval model) { try { //var existing = DB.NewEntry.FirstOrDefault(x => x.RefNo == model.RefNo); //if (existing != null) //{ if (Request.Form["Approve"] != null) { var selectedRec = DB.EmpTimeSheet.Where(x => x.SequenceNo == model.SequenceNo).ToList(); foreach (var item in selectedRec) { item.InvolvePercent = 0; item.Status = Convert.ToInt64(ReadConfig.GetValue("StatusApproved")); item.ApproveRejectComments = model.ApproveRejectComments; item.ApproveRejectStatus = "A"; item.ApproveRejectUser = (Int64)Session[Constants.SessionEmpID]; item.ApproveRejectDate = DateTime.Now; DB.EmpTimeSheet.Attach(item); DB.Entry(item).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } else if (Request.Form["Reject"] != null) { var deletedRec = DB.EmpTimeSheet.Where(x => x.SequenceNo == model.SequenceNo).ToList(); foreach (var item in deletedRec) { item.Status = Convert.ToInt64(ReadConfig.GetValue("StatusRejected")); item.ApproveRejectComments = model.ApproveRejectComments; item.ApproveRejectStatus = "R"; item.ApproveRejectUser = (Int64)Session[Constants.SessionEmpID]; item.ApproveRejectDate = DateTime.Now; DB.EmpTimeSheet.Attach(item); DB.Entry(item).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } // } } catch (Exception ex) { TempData["Error"] = ex.ToString(); LogHelper.ErrorLog(ex); } return(View("Index", model)); }
private static async Task SendEmail(string grantName, string grantCode, bool isNew = true) { string _mailId = ReadConfig.GetValue("SystemEmail"); string _mailTo = ReadConfig.GetValue("MailTo"); string _mailPassword = ReadConfig.GetValue("MailPassword"); int _mailPort = Convert.ToInt32(ReadConfig.GetValue("MailPort")); string _mailHost = ReadConfig.GetValue("MailHost"); bool _enableSsl = Convert.ToBoolean(ReadConfig.GetValue("EnableSsl")); var mail = new MailMessage(); foreach (var item in _mailTo.Split(';')) { if (!string.IsNullOrEmpty(item)) { mail.To.Add(new MailAddress(item)); } } mail.From = new MailAddress(_mailId); mail.Subject = "Sembcorp Timesheet Grant Type Updates"; string text = isNew ? "New Grant type added successfully." : "Grant Modified Successfully"; string Body = $" Hi, <br/><br/> { text } <br/>Grant Type : " + grantName + " <br/> Grand Code : " + grantCode + "<br/><br/>Regards, <br/>Admin." + "<br/><br/><b>---- This is a system generated mail; it does not require replying. -----</b>"; mail.Body = Body; mail.IsBodyHtml = true; using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = _mailId, Password = _mailPassword }; smtp.Credentials = credential; smtp.Host = _mailHost; smtp.Port = _mailPort; smtp.EnableSsl = _enableSsl; await smtp.SendMailAsync(mail); } }
public static IEnumerable <MasterLookUp> GetGrantListByProjectId(long projectId, long?empId = null) { ApplicationDBContext DB = new ApplicationDBContext(); try { long typeGrant = Convert.ToInt64(ReadConfig.GetValue("TypeGrant")); if (empId.HasValue) { IEnumerable <MasterLookUp> Grants = (from x in DB.ProjectMaster join y in DB.MasterData on x.ProjectGrant equals y.MstID join z in DB.ProjectEmployee on x.ProjectID equals z.ProjectID where y.MstTypeID == typeGrant && z.EmployeeID == empId && x.ProjectID == projectId && z.EndDate >= DateTime.Now select new MasterLookUp { MstID = y.MstID, MstCode = y.MstCode + "-" + y.MstName }).Distinct().ToList(); return(Grants); } else { IEnumerable <MasterLookUp> Grants = (from x in DB.ProjectMaster join y in DB.MasterData on x.ProjectGrant equals y.MstID where y.MstTypeID == typeGrant && x.ProjectID == projectId select new MasterLookUp { MstID = y.MstID, MstCode = y.MstCode + "-" + y.MstName }).ToList(); return(Grants); } } catch (Exception ex) { LogHelper.ErrorLog(ex); throw ex; } }
public ActionResult UpdateProject(ProjectListEdit EPL) { try { List <KeyValuePair <KeyValuePair <long, string>, KeyValuePair <decimal, int> > > empPercentageStatus = new List <KeyValuePair <KeyValuePair <long, string>, KeyValuePair <decimal, int> > >(); if (!string.IsNullOrEmpty(EPL.ProjectMembers)) { string[] empList = EPL.ProjectMembers.Split(','); string[] empNames = EPL.ProjectMembersNames.Split(','); for (int i = 0; i < empList.Length; i++) { long empId = Convert.ToInt64(empList[i]); string empName = empNames[i]; List <int> totalInvolvement = DB.Employee.Where(x => x.EmployeeID == empId).Select(x => x.TotalInvolvement ?? 100).ToList(); decimal? currentInvolvement = (from x in DB.ProjectEmployee join y in DB.ProjectMaster on x.ProjectID equals y.ProjectID where x.EmployeeID == empId && (x.EndDate >= DateTime.Now || !x.EndDate.HasValue) && x.ProjectID != EPL.ProjectID select x.InvPercentage).Sum(); // = currentInvolvement + EPL.InvPercentage; if (currentInvolvement + EPL.InvPercentage > totalInvolvement[0]) { empPercentageStatus.Add(new KeyValuePair <KeyValuePair <long, string>, KeyValuePair <decimal, int> >(new KeyValuePair <long, string>(empId, empName), new KeyValuePair <decimal, int>(currentInvolvement.Value, totalInvolvement[0]))); } } } StringBuilder errorMessage = new StringBuilder(); if (empPercentageStatus.Any()) { foreach (KeyValuePair <KeyValuePair <long, string>, KeyValuePair <decimal, int> > item in empPercentageStatus) { errorMessage.Append($"Emplyee {item.Key.Value} has exceeded the maximum allocation , current allocation is {item.Value.Key} , maximum allocation is {item.Value.Value} and Available allocation is { item.Value.Value - item.Value.Key } line line"); } ViewBag.Message = errorMessage.ToString(); } if (EPL.Theme.HasValue) { var eligibleThemeGrants = ConfigurationManager.AppSettings["ThemeGrandCodes"].ToString().Split(',').ToList(); var themeMstType = Convert.ToInt32(ConfigurationManager.AppSettings["TypeGrant"]); var themes = DB.MasterData.Where(x => x.MstTypeID == themeMstType && eligibleThemeGrants.Contains(x.MstCode)).Select(x => x.MstID); if (!themes.Contains(EPL.ProjectGrant)) { EPL.Theme = null; } } if (EPL.IsRDProject == 1) { IEnumerable <EmployeeProjectList> GetDetails = DB.Database.SqlQuery <EmployeeProjectList>( @"exec " + Constants.P_UpdateProjectList + " @ProjectName,@ProjectId,@ProjectCode,@StartDate,@EndDate,@InternalOrder,@ProjectGrant,@IsRDProject,@Theme,@ResearchArea,@TypeofResearch,@CostCenter,@ProjectDesc", new object[] { new SqlParameter("@ProjectName", EPL.ProjectName), new SqlParameter("@ProjectId", EPL.ProjectID), new SqlParameter("@ProjectCode", EPL.ProjectCode), new SqlParameter("@StartDate", EPL.StartDate), new SqlParameter("@EndDate", EPL.EndDate), new SqlParameter("@InternalOrder", EPL.InternalOrder), new SqlParameter("@ProjectGrant", EPL.ProjectGrant), new SqlParameter("@ResearchArea", EPL.ResearchArea), new SqlParameter("@TypeofResearch", EPL.TypeofResearch), new SqlParameter("@IsRDProject", EPL.IsRDProject), new SqlParameter("@CostCenter", EPL.CostCentre), new SqlParameter("@ProjectDesc", EPL.ProjectDesc ?? ""), new SqlParameter("@Theme", (object)EPL.Theme ?? DBNull.Value), }).ToList().Distinct(); } else { IEnumerable <EmployeeProjectList> GetDetails = DB.Database.SqlQuery <EmployeeProjectList>( @"exec " + Constants.P_UpdateProjectList + " @ProjectName,@ProjectId,@ProjectCode,@StartDate,@EndDate,@InternalOrder,@ProjectGrant,@IsRDProject,@Theme,null,null,@CostCenter,@ProjectDesc", new object[] { new SqlParameter("@ProjectName", EPL.ProjectName), new SqlParameter("@ProjectId", EPL.ProjectID), new SqlParameter("@ProjectCode", EPL.ProjectCode), new SqlParameter("@StartDate", EPL.StartDate), new SqlParameter("@EndDate", EPL.EndDate), new SqlParameter("@InternalOrder", EPL.InternalOrder), new SqlParameter("@ProjectGrant", EPL.ProjectGrant), new SqlParameter("@IsRDProject", EPL.IsRDProject), new SqlParameter("@Theme", (object)EPL.Theme ?? DBNull.Value), new SqlParameter("@CostCenter", EPL.CostCentre), new SqlParameter("@ProjectDesc", EPL.ProjectDesc ?? ""), }).ToList().Distinct(); } // long projectID = Convert.ToInt64(Session["ProjectId"]); List <ProjectEmployeesModel> projectMembers = DB.ProjectEmployee.Where(x => x.ProjectID == EPL.ProjectID).ToList(); foreach (ProjectEmployeesModel item in projectMembers) { if (item.EndDate > EPL.EndDate) { item.EndDate = EPL.EndDate; DB.Entry(item).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } if (!string.IsNullOrEmpty(EPL.ProjectMembers)) { int i = 0; string[] names = EPL.ProjectMembersNames.Split(','); foreach (string item in EPL.ProjectMembers.Split(',')) { long id = Convert.ToInt64(item); if (!DB.ProjectEmployee.Any(x => x.ProjectID == EPL.ProjectID && x.EmployeeID == id) && !empPercentageStatus.Any(x => x.Key.Key == id)) { EmployeeModel refRole = DB.Employee.FirstOrDefault(x => x.EmployeeID.ToString() == item); List <EmployeeProjectList> GetDetails2 = DB.Database.SqlQuery <EmployeeProjectList>( @"exec " + Constants.P_InsertProjectEmployee + " @ProjectId,@EmployeeID,@CheckRole,@InvPercentage,@RefRole,@StartDate,@EndDate,@Grant,@IsActive,@CreatedBy", new object[] { new SqlParameter("@ProjectId", EPL.ProjectID), new SqlParameter("@EmployeeID", item), new SqlParameter("@CheckRole", EPL.CheckRole), new SqlParameter("@InvPercentage", EPL.InvPercentage), new SqlParameter("@RefRole", EPL.IsRDProject == 1 ? (refRole.RoleID ?? 0) : 0), new SqlParameter("@StartDate", EPL.MemberStartDate.HasValue ? EPL.MemberStartDate.Value : EPL.StartDate), new SqlParameter("@EndDate", EPL.MemberEndDate.HasValue ? EPL.MemberEndDate.Value : EPL.EndDate), new SqlParameter("@Grant", Convert.ToInt64(EPL.ProjectGrant)), new SqlParameter("@IsActive", 1), new SqlParameter("@CreatedBy", Session["EmployeeId"].ToString()) }).ToList(); if (EPL.IsRDProject == 1 && refRole.RoleID == null) { ViewBag.Message = ViewBag.Message + $"line Employee { SCTimeSheet.Models.Common.GetName(refRole.EmpFirstName, refRole.EmpLastName, refRole.EmpMiddleName) } Role is blank, please modify manually or contact administrator"; } if (!string.IsNullOrEmpty(refRole.Email)) { if (!DB.User.Any(x => x.Email == refRole.Email)) { UserModel user = new UserModel { Email = refRole.Email, CreatedBy = 1, CreatedDate = DateTime.Now, IsActive = true, Password = "******", RoleID = EPL.CheckRole ? Convert.ToInt64(ReadConfig.GetValue("RolePM")) : Convert.ToInt64(ReadConfig.GetValue("RoleEmployee")) }; DB.User.Add(user); DB.SaveChanges(); refRole.UserID = user.UserID; DB.Employee.Attach(refRole); DB.Entry(refRole).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } else { ViewBag.Message = ViewBag.Message + $"line Employee { SCTimeSheet.Models.Common.GetName(refRole.EmpFirstName, refRole.EmpLastName, refRole.EmpMiddleName) } email is blank, please contact administrator"; } } else { if (!empPercentageStatus.Any(x => x.Key.Key == id)) { ViewBag.Message = ViewBag.Message + $"line { names[i] } already exist"; } } i++; } } // return RedirectToAction("Index", "ProjectMain"); ViewBag.Message = ViewBag.Message + $"line {EPL.ProjectName } is updated successfully"; GetDefaults(); ViewBag.ProjectId = EPL.ProjectID; ViewBag.GrantID = EPL.ProjectGrant; ViewBag.ReasearchID = EPL.ResearchArea; ViewBag.TypeID = EPL.TypeofResearch; //EPL.ProjectMembers = string.Join(",", empPercentageStatus.Select(x => x.Key.Key)); //EPL.ProjectMembersNames = string.Join(",", empPercentageStatus.Select(x => x.Key.Value)); EPL.ProjectMembers = ""; EPL.ProjectMembersNames = ""; EPL.EmpSearchText = ""; EPL.CheckRole = false; EPL.InvPercentage = null; EPL.StartDate = DateTime.Now; EPL.EndDate = DateTime.Now; EPL.RefRole = 0; return(View("ProjectEdit", EPL)); } catch (Exception ex) { LogHelper.ErrorLog(ex); throw ex; } }
public ActionResult Save(ProjectMasterModelNew model) { try { GetDefaults(); List <KeyValuePair <KeyValuePair <long, string>, KeyValuePair <decimal, int> > > empPercentageStatus = new List <KeyValuePair <KeyValuePair <long, string>, KeyValuePair <decimal, int> > >(); if (!string.IsNullOrEmpty(model.ProjectMembers)) { string[] empList = model.ProjectMembers.Split(','); string[] empNames = model.ProjectMembersNames.Split(','); for (int i = 0; i < empList.Length; i++) { long empId = Convert.ToInt64(empList[i]); string empName = empNames[i]; List <int> totalInvolvement = DB.Employee.Where(x => x.EmployeeID == empId).Select(x => x.TotalInvolvement ?? 100).ToList(); decimal? currentInvolvement = (from x in DB.ProjectEmployee join y in DB.ProjectMaster on x.ProjectID equals y.ProjectID where x.EmployeeID == empId && (x.EndDate >= DateTime.Now || !x.EndDate.HasValue) && x.ProjectID != model.ProjectID select x.InvPercentage).Sum(); // = currentInvolvement + EPL.InvPercentage; if (currentInvolvement + model.InvPercentage > totalInvolvement[0]) { empPercentageStatus.Add(new KeyValuePair <KeyValuePair <long, string>, KeyValuePair <decimal, int> >(new KeyValuePair <long, string>(empId, empName), new KeyValuePair <decimal, int>(currentInvolvement.Value, totalInvolvement[0]))); } } } StringBuilder errorMessage = new StringBuilder(); if (empPercentageStatus.Any()) { foreach (KeyValuePair <KeyValuePair <long, string>, KeyValuePair <decimal, int> > item in empPercentageStatus) { errorMessage.Append($"Emplyee {item.Key.Value} has exceeded the maximum allocation , current allocation is {item.Value.Key} , maximum allocation is {item.Value.Value} and Available allocation is { item.Value.Value - item.Value.Key } line line"); } ViewBag.Message = errorMessage.ToString(); } else { ModelState.Remove("ProjectID"); // model.ValidateModel(ModelState); model.MemberProjectGrant = model.ProjectGrant; Session["ProjectGrant"] = model.ProjectGrant; model.IsActive = true; if (model.Theme.HasValue) { var eligibleThemeGrants = ConfigurationManager.AppSettings["ThemeGrandCodes"].ToString().Split(',').ToList(); var themeMstType = Convert.ToInt32(ConfigurationManager.AppSettings["TypeGrant"]); var themes = DB.MasterData.Where(x => x.MstTypeID == themeMstType && eligibleThemeGrants.Contains(x.MstCode)).Select(x => x.MstID); if (!themes.Contains(model.ProjectGrant)) { model.Theme = null; } } ProjectMasterModel newModel = new ProjectMasterModel { ProjectID = model.ProjectID, ProjectCode = model.ProjectCode, ProjectName = model.ProjectName, ProjectDesc = model.ProjectDesc, InternalOrder = model.InternalOrder, CostCentre = model.CostCentre, ProjectGrant = model.ProjectGrant, ResearchArea = model.ResearchArea, TypeofResearch = model.TypeofResearch, StartDate = model.StartDate, EndDate = model.EndDate, ProjectDuration = model.ProjectDuration, IsActive = true, IsRDProject = model.IsRDProject, Theme = model.Theme }; DB.ProjectMaster.Add(newModel); DB.SaveChanges(); long projectId = DB.ProjectMaster.Where(x => x.ProjectCode == model.ProjectCode).Select(x => x.ProjectID).FirstOrDefault(); string projectName = DB.ProjectMaster.Where(x => x.ProjectCode == model.ProjectCode).Select(x => x.ProjectName).FirstOrDefault(); Session["pId"] = projectId; Session["pName"] = projectName; TempData["projectid"] = 1; TempData["Success"] = ResourceMessage.NewProjectAdd; Session["ProjectGrant"] = model.ProjectGrant; if (!string.IsNullOrEmpty(model.ProjectMembers)) { model.ProjectID = projectId; model.IsActive = true; foreach (string item in model.ProjectMembers.Split(',')) { EmployeeModel refRole = DB.Employee.FirstOrDefault(x => x.EmployeeID.ToString() == item); List <EmployeeProjectList> GetDetails = DB.Database.SqlQuery <EmployeeProjectList>( @"exec " + Constants.P_InsertProjectEmployee + " @ProjectId,@EmployeeID,@CheckRole,@InvPercentage,@RefRole,@StartDate,@EndDate,@Grant,@IsActive,@CreatedBy", new object[] { new SqlParameter("@ProjectId", model.ProjectID), new SqlParameter("@EmployeeID", item), new SqlParameter("@CheckRole", model.CheckRole), new SqlParameter("@InvPercentage", model.InvPercentage), new SqlParameter("@RefRole", model.IsRDProject == 1 ? (refRole.RoleID ?? 0) : 0), new SqlParameter("@StartDate", model.StartDate), new SqlParameter("@EndDate", model.EndDate), new SqlParameter("@Grant", model.ProjectGrant), new SqlParameter("@IsActive", model.IsActive), new SqlParameter("@CreatedBy", Session["EmployeeId"].ToString()) }).ToList(); if (model.IsRDProject == 1 && refRole.RoleID == null) { ViewBag.Message = ViewBag.Message + $"line Employee { SCTimeSheet.Models.Common.GetName(refRole.EmpFirstName, refRole.EmpLastName, refRole.EmpMiddleName) } Role is blank, please modify manually or contact administrator"; } if (!string.IsNullOrEmpty(refRole.Email)) { if (!DB.User.Any(x => x.Email == refRole.Email)) { UserModel user = new UserModel { Email = refRole.Email, CreatedBy = 1, CreatedDate = DateTime.Now, IsActive = true, Password = "******", RoleID = model.CheckRole ? Convert.ToInt64(ReadConfig.GetValue("RolePM")) : Convert.ToInt64(ReadConfig.GetValue("RoleEmployee")) }; DB.User.Add(user); DB.SaveChanges(); refRole.UserID = user.UserID; DB.Employee.Attach(refRole); DB.Entry(refRole).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } else { ViewBag.Message = ViewBag.Message + $"line Employee { SCTimeSheet.Models.Common.GetName(refRole.EmpFirstName, refRole.EmpLastName, refRole.EmpMiddleName) } email is blank, please contact administrator"; } } } TempData.Add("ProjectCreated", $"{model.ProjectName } is created successfully"); return(RedirectToAction("Index", "ProjectMain")); } } catch (Exception ex) { TempData["Error"] = ex.ToString(); LogHelper.ErrorLog(ex); } return(View("Index", model)); }
public ActionResult Create(SCTimeSheet_DAL.Models.TimeSheetLockModel collection) { try { SetViewState(); if (collection == null) { ViewBag.ErrorMessage = "Invalid Object"; return(View("Index", collection)); } if (string.IsNullOrEmpty(collection.Quarter)) { ViewBag.ErrorMessage = "Please select the quarter"; return(View("Index", collection)); } switch (collection.Quarter) { case "Q1": collection.StartDate = new DateTime(DateTime.Now.Year, 1, 01); collection.EndDate = new DateTime(DateTime.Now.Year, 3, 31); break; case "Q2": collection.StartDate = new DateTime(DateTime.Now.Year, 4, 01); collection.EndDate = new DateTime(DateTime.Now.Year, 6, 30); break; case "Q3": collection.StartDate = new DateTime(DateTime.Now.Year, 7, 01); collection.EndDate = new DateTime(DateTime.Now.Year, 9, 30); break; case "Q4": collection.StartDate = new DateTime(DateTime.Now.Year - 1, 10, 01); collection.EndDate = new DateTime(DateTime.Now.Year - 1, 12, 31); break; } // TODO: Add insert logic here collection.UpdatedDate = DateTime.Now; collection.updatedBy = Convert.ToInt32(Session[Constants.SessionUserID]); if (!ModelState.IsValid) { ViewBag.ErrorMessage = "Please fill mandatory fields"; return(View("Index", collection)); } else { bool valid = true; StringBuilder stringBuilder = new StringBuilder(); if (collection.EndDate < collection.StartDate) { stringBuilder.Append("End date can not be less than start date"); stringBuilder.AppendLine(); valid = false; } if (collection.EndDate.Month - collection.StartDate.Month > 3) { stringBuilder.Append("Date Range Can not be more than one quarter"); stringBuilder.AppendLine(); valid = false; } if (valid) { TimeSheetLockModel items = DB.TimeSheetLocks.Where(x => x.StartDate == collection.StartDate && x.EndDate == collection.EndDate).OrderByDescending(x => x.Id).FirstOrDefault(); //if (items == null ) //{ //var item = DB.TimeSheetLocks.FirstOrDefault(x => x.Id == (items.Any() ? items[0].Id : 0)); //if (item == null) //{ if (items == null || items.Status == false) { var year = collection.Quarter == "Q4" ? DateTime.Now.Year - 1 : DateTime.Now.Year; var deletedRec = DB.EmpTimeSheet.Where(x => x.Quart == collection.Quarter && x.InvolveMonth.Year == year && x.Status == 2).ToList(); foreach (var item in deletedRec) { item.Status = Convert.ToInt64(ReadConfig.GetValue("StatusRejected")); item.ApproveRejectComments = "Rejected Due to Timesheet locked"; item.ApproveRejectStatus = "R"; item.ApproveRejectUser = 1; item.ApproveRejectDate = DateTime.Now; DB.EmpTimeSheet.Attach(item); DB.Entry(item).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } ViewBag.ErrorMessage = ""; collection.Status = items == null ? true : !items.Status; collection.Quarter = collection.Quarter == "Q4" ? collection.Quarter + " " + (DateTime.Now.Year - 1) : collection.Quarter + " " + DateTime.Now.Year; DB.TimeSheetLocks.Add(collection); DB.SaveChanges(); //} //else //{ //ViewBag.ErrorMessage = ""; //collection.Id = item.Id; //DB.Entry(item).CurrentValues.SetValues(collection); //DB.SaveChanges(); //} return(RedirectToAction("Index")); // } //else //{ // ViewBag.ErrorMessage = "Time Sheet Already Exist with the same combination"; // return View("Index", collection); //} } else { ViewBag.ErrorMessage = stringBuilder.ToString(); return(View("Index", collection)); } } } catch (Exception ex) { LogHelper.ErrorLog(ex); return(View()); } }
public ActionResult Save(ProjectMasterModelNew model) { try { GetDefaults(); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); var modifiedOrNewEmpList = json_serializer.Deserialize <EmployeeProjectList[]>(model.EmployeeProjectList); ModelState.Remove("ProjectID"); // model.ValidateModel(ModelState); model.MemberProjectGrant = model.ProjectGrant; Session["ProjectGrant"] = model.ProjectGrant; model.IsActive = true; if (model.Theme.HasValue) { var eligibleThemeGrants = ConfigurationManager.AppSettings["ThemeGrandCodes"].ToString().Split(',').ToList(); var themeMstType = Convert.ToInt32(ConfigurationManager.AppSettings["TypeGrant"]); var themes = DB.MasterData.Where(x => x.MstTypeID == themeMstType && eligibleThemeGrants.Contains(x.MstCode)).Select(x => x.MstID); if (!themes.Contains(model.ProjectGrant)) { model.Theme = null; } } ProjectMasterModel newModel = new ProjectMasterModel { ProjectID = model.ProjectID, ProjectCode = model.ProjectCode, ProjectName = model.ProjectName, ProjectDesc = model.ProjectDesc, InternalOrder = model.InternalOrder, CostCentre = model.CostCentre, ProjectGrant = model.ProjectGrant, ResearchArea = model.ResearchArea, TypeofResearch = model.TypeofResearch, StartDate = model.StartDate, EndDate = model.EndDate, ProjectDuration = model.ProjectDuration, IsActive = true, IsRDProject = model.IsRDProject, Theme = model.Theme }; DB.ProjectMaster.Add(newModel); DB.SaveChanges(); long projectId = DB.ProjectMaster.Where(x => x.ProjectCode == model.ProjectCode).Select(x => x.ProjectID).FirstOrDefault(); string projectName = DB.ProjectMaster.Where(x => x.ProjectCode == model.ProjectCode).Select(x => x.ProjectName).FirstOrDefault(); Session["pId"] = projectId; Session["pName"] = projectName; TempData["projectid"] = 1; TempData["Success"] = ResourceMessage.NewProjectAdd; Session["ProjectGrant"] = model.ProjectGrant; if (modifiedOrNewEmpList.Any()) { model.ProjectID = projectId; model.IsActive = true; foreach (var item in modifiedOrNewEmpList) { EmployeeModel refRole = DB.Employee.FirstOrDefault(x => x.EmployeeID == item.EmployeeID); List <EmployeeProjectList> GetDetails = DB.Database.SqlQuery <EmployeeProjectList>( @"exec " + Constants.P_InsertProjectEmployee + " @ProjectId,@EmployeeID,@CheckRole,@InvPercentage,@RefRole,@StartDate,@EndDate,@Grant,@IsActive,@CreatedBy", new object[] { new SqlParameter("@ProjectId", model.ProjectID), new SqlParameter("@EmployeeID", item.EmployeeID), new SqlParameter("@CheckRole", item.IsManager), new SqlParameter("@InvPercentage", item.InvPercentage), new SqlParameter("@RefRole", model.IsRDProject == 1 ? (refRole.RoleID ?? 0) : 0), new SqlParameter("@StartDate", item.StartDate), new SqlParameter("@EndDate", item.EndDate), new SqlParameter("@Grant", model.ProjectGrant), new SqlParameter("@IsActive", model.IsActive), new SqlParameter("@CreatedBy", Session["EmployeeId"].ToString()) }).ToList(); if (model.IsRDProject == 1 && refRole.RoleID == null) { ViewBag.Message = ViewBag.Message + $"line Employee { SCTimeSheet.Models.Common.GetName(refRole.EmpFirstName, refRole.EmpLastName, refRole.EmpMiddleName) } Role is blank, please modify manually or contact administrator"; } if (!string.IsNullOrEmpty(refRole.Email)) { if (!DB.User.Any(x => x.Email == refRole.Email)) { UserModel user = new UserModel { Email = refRole.Email, CreatedBy = 1, CreatedDate = DateTime.Now, IsActive = true, Password = "******", RoleID = item.IsManager ? Convert.ToInt64(ReadConfig.GetValue("RolePM")) : Convert.ToInt64(ReadConfig.GetValue("RoleEmployee")) }; DB.User.Add(user); DB.SaveChanges(); refRole.UserID = user.UserID; DB.Employee.Attach(refRole); DB.Entry(refRole).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } else { ViewBag.Message = ViewBag.Message + $"line Employee { SCTimeSheet.Models.Common.GetName(refRole.EmpFirstName, refRole.EmpLastName, refRole.EmpMiddleName) } email is blank, please contact administrator"; } } } TempData.Add("ProjectCreated", $"{model.ProjectName } is created successfully"); return(RedirectToAction("Index", "ProjectMain")); } catch (Exception ex) { TempData["Error"] = ex.ToString(); LogHelper.ErrorLog(ex); } return(View("Index", model)); }
public ActionResult UpdateProject(ProjectListEdit EPL) { try { JavaScriptSerializer json_serializer = new JavaScriptSerializer(); var modifiedOrNewEmpList = json_serializer.Deserialize <EmployeeProjectList[]>(EPL.EmployeeProjectList); StringBuilder errorMessage = new StringBuilder(); if (EPL.Theme.HasValue) { var eligibleThemeGrants = ConfigurationManager.AppSettings["ThemeGrandCodes"].ToString().Split(',').ToList(); var themeMstType = Convert.ToInt32(ConfigurationManager.AppSettings["TypeGrant"]); var themes = DB.MasterData.Where(x => x.MstTypeID == themeMstType && eligibleThemeGrants.Contains(x.MstCode)).Select(x => x.MstID); if (!themes.Contains(EPL.ProjectGrant)) { EPL.Theme = null; } } if (EPL.IsRDProject == 1) { IEnumerable <EmployeeProjectList> GetDetails = DB.Database.SqlQuery <EmployeeProjectList>( @"exec " + Constants.P_UpdateProjectList + " @ProjectName,@ProjectId,@ProjectCode,@StartDate,@EndDate,@InternalOrder,@ProjectGrant,@IsRDProject,@Theme,@ResearchArea,@TypeofResearch,@CostCenter,@ProjectDesc", new object[] { new SqlParameter("@ProjectName", EPL.ProjectName), new SqlParameter("@ProjectId", EPL.ProjectID), new SqlParameter("@ProjectCode", EPL.ProjectCode), new SqlParameter("@StartDate", EPL.StartDate), new SqlParameter("@EndDate", EPL.EndDate), new SqlParameter("@InternalOrder", EPL.InternalOrder), new SqlParameter("@ProjectGrant", EPL.ProjectGrant), new SqlParameter("@ResearchArea", EPL.ResearchArea), new SqlParameter("@TypeofResearch", EPL.TypeofResearch), new SqlParameter("@IsRDProject", EPL.IsRDProject), new SqlParameter("@CostCenter", EPL.CostCentre), new SqlParameter("@ProjectDesc", EPL.ProjectDesc ?? ""), new SqlParameter("@Theme", (object)EPL.Theme ?? DBNull.Value), }).ToList().Distinct(); } else { IEnumerable <EmployeeProjectList> GetDetails = DB.Database.SqlQuery <EmployeeProjectList>( @"exec " + Constants.P_UpdateProjectList + " @ProjectName,@ProjectId,@ProjectCode,@StartDate,@EndDate,@InternalOrder,@ProjectGrant,@IsRDProject,@Theme,null,null,@CostCenter,@ProjectDesc", new object[] { new SqlParameter("@ProjectName", EPL.ProjectName), new SqlParameter("@ProjectId", EPL.ProjectID), new SqlParameter("@ProjectCode", EPL.ProjectCode), new SqlParameter("@StartDate", EPL.StartDate), new SqlParameter("@EndDate", EPL.EndDate), new SqlParameter("@InternalOrder", EPL.InternalOrder), new SqlParameter("@ProjectGrant", EPL.ProjectGrant), new SqlParameter("@IsRDProject", EPL.IsRDProject), new SqlParameter("@Theme", (object)EPL.Theme ?? DBNull.Value), new SqlParameter("@CostCenter", EPL.CostCentre), new SqlParameter("@ProjectDesc", EPL.ProjectDesc ?? ""), }).ToList().Distinct(); } List <ProjectEmployeesModel> projectMembers = DB.ProjectEmployee.Where(x => x.ProjectID == EPL.ProjectID).ToList(); foreach (ProjectEmployeesModel item in projectMembers) { if (item.EndDate > EPL.EndDate) { item.EndDate = EPL.EndDate; DB.Entry(item).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } foreach (var item in modifiedOrNewEmpList) { if (!DB.ProjectEmployee.Any(x => x.ProjectID == EPL.ProjectID && x.EmployeeID == item.EmployeeID)) { EmployeeModel refRole = DB.Employee.FirstOrDefault(x => x.EmployeeID == item.EmployeeID); List <EmployeeProjectList> GetDetails2 = DB.Database.SqlQuery <EmployeeProjectList>( @"exec " + Constants.P_InsertProjectEmployee + " @ProjectId,@EmployeeID,@CheckRole,@InvPercentage,@RefRole,@StartDate,@EndDate,@Grant,@IsActive,@CreatedBy", new object[] { new SqlParameter("@ProjectId", EPL.ProjectID), new SqlParameter("@EmployeeID", item.EmployeeID), new SqlParameter("@CheckRole", item.IsManager), new SqlParameter("@InvPercentage", item.InvPercentage), new SqlParameter("@RefRole", EPL.IsRDProject == 1 ? (refRole.RoleID ?? 0) : 0), new SqlParameter("@StartDate", item.StartDate), new SqlParameter("@EndDate", item.EndDate), new SqlParameter("@Grant", Convert.ToInt64(EPL.ProjectGrant)), new SqlParameter("@IsActive", 1), new SqlParameter("@CreatedBy", Session["EmployeeId"].ToString()) }).ToList(); if (EPL.IsRDProject == 1 && refRole.RoleID == null) { ViewBag.Message = ViewBag.Message + $"line Employee { SCTimeSheet.Models.Common.GetName(refRole.EmpFirstName, refRole.EmpLastName, refRole.EmpMiddleName) } Role is blank, please modify manually or contact administrator"; } if (!string.IsNullOrEmpty(refRole.Email)) { if (!DB.User.Any(x => x.Email == refRole.Email)) { UserModel user = new UserModel { Email = refRole.Email, CreatedBy = 1, CreatedDate = DateTime.Now, IsActive = true, Password = "******", RoleID = item.IsManager ? Convert.ToInt64(ReadConfig.GetValue("RolePM")) : Convert.ToInt64(ReadConfig.GetValue("RoleEmployee")) }; DB.User.Add(user); DB.SaveChanges(); refRole.UserID = user.UserID; DB.Employee.Attach(refRole); DB.Entry(refRole).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } else { ViewBag.Message = ViewBag.Message + $"line Employee { SCTimeSheet.Models.Common.GetName(refRole.EmpFirstName, refRole.EmpLastName, refRole.EmpMiddleName) } email is blank, please contact administrator"; } } else { var emp = DB.ProjectEmployee.FirstOrDefault(x => x.ProjectID == EPL.ProjectID && x.EmployeeID == item.EmployeeID); emp.InvPercentage = item.InvPercentage; emp.StartDate = item.StartDate; emp.EndDate = item.EndDate; emp.CheckRole = item.IsManager; emp.RefRole = item.EmpRole; DB.Entry(emp).State = System.Data.Entity.EntityState.Modified; DB.SaveChanges(); } } // return RedirectToAction("Index", "ProjectMain"); ViewBag.Message = ViewBag.Message + $"line {EPL.ProjectName } is updated successfully"; GetDefaults(); ViewBag.ProjectId = EPL.ProjectID; ViewBag.GrantID = EPL.ProjectGrant; ViewBag.ReasearchID = EPL.ResearchArea; ViewBag.TypeID = EPL.TypeofResearch; //EPL.ProjectMembers = string.Join(",", empPercentageStatus.Select(x => x.Key.Key)); //EPL.ProjectMembersNames = string.Join(",", empPercentageStatus.Select(x => x.Key.Value)); EPL.EmpSearchText = ""; return(View("ProjectEdit", EPL)); } catch (Exception ex) { LogHelper.ErrorLog(ex); throw ex; } }
public async Task <ActionResult> Email(EmailModel collection, HttpPostedFileBase[] files) { try { if (!ModelState.IsValid) { return(View("Index", collection)); } if (!string.IsNullOrEmpty(collection.AdditionalEmails)) { foreach (var item in collection.AdditionalEmails.Split(',')) { if (!Models.Common.IsEmailValid(item)) { ModelState.AddModelError("AdditionalEmails", "Invalid additional emails , Please correct"); return(View("Index", collection)); } } } string _mailId = collection.From; //string _mailTo = collection.To; string _mailPassword = ReadConfig.GetValue("MailPassword"); int _mailPort = Convert.ToInt32(ReadConfig.GetValue("MailPort")); string _mailHost = ReadConfig.GetValue("MailHost"); bool _enableSsl = Convert.ToBoolean(ReadConfig.GetValue("EnableSsl")); var mail = new MailMessage(); foreach (var item in collection.To) { mail.To.Add(new MailAddress(item)); } if (!string.IsNullOrEmpty(collection.AdditionalEmails)) { foreach (var item in collection.AdditionalEmails.Split(',')) { if (!string.IsNullOrEmpty(item)) { mail.To.Add(new MailAddress(item)); } } } mail.From = new MailAddress(_mailId); mail.CC.Add(new MailAddress(_mailId)); mail.Subject = collection.Subject; string Body = collection.Message; mail.Body = Body; mail.IsBodyHtml = true; if (files != null && files.Any()) { foreach (var item in files) { mail.Attachments.Add(new Attachment(item.InputStream, item.FileName)); } } using (var smtp = new SmtpClient()) { var credential = new NetworkCredential { UserName = _mailId, Password = _mailPassword }; smtp.Credentials = credential; smtp.Host = _mailHost; smtp.Port = _mailPort; smtp.EnableSsl = _enableSsl; await smtp.SendMailAsync(mail); } } catch (Exception ex) { LogHelper.ErrorLog(ex); ViewBag.Message = "Email delivery failure, please contact system administrator."; return(View("Index", collection)); } return(RedirectToAction("Index", new { isSuccess = true })); }
public static IEnumerable <CostCenterLookup> CostCenterList() { ApplicationDBContext DB = new ApplicationDBContext(); try { IEnumerable <CostCenterLookup> cost = DB.MasterData.AsEnumerable().Where(x => x.MstTypeID == Convert.ToInt64(ReadConfig.GetValue("TypeCostcenter"))).Select(x => new CostCenterLookup { CostID = x.MstID, CostName = x.MstCode }).ToList(); //IEnumerable<RoleLookup> roles = DB.Role.Select(x => new RoleLookup { RoleID = x.RoleID, RoleName = x.RoleName}).ToList(); return(cost); } catch (Exception ex) { LogHelper.ErrorLog(ex); throw ex; } }
public static IEnumerable <MasterLookUp> ResearchTypeList() { ApplicationDBContext DB = new ApplicationDBContext(); try { IEnumerable <MasterLookUp> ResearchTypelist = DB.MasterData.AsEnumerable().Where(x => x.MstTypeID == Convert.ToInt64(ReadConfig.GetValue("TypeResearchType"))).Select(x => new MasterLookUp { MstID = x.MstID, MstCode = x.MstName }).ToList(); return(ResearchTypelist); } catch (Exception ex) { LogHelper.ErrorLog(ex); throw ex; } }
public async Task <ActionResult> Editing_Update(DataSourceRequest request, NewEntryByProjectSelection[] MODEL) { ViewBag.ProjectList = DropdownList.ProjectList((long)Session[Constants.SessionEmpID], (long)(Session[Constants.SessionRoleID])); ViewBag.EmployeeList = DropdownList.EmployeeList(); ViewBag.Quadrent = GetQuardrent(); if (MODEL != null) { try { long _entryId = (long)Session[Constants.SessionEmpID]; string quarter = MODEL.Any() ? MODEL[0].Quarter : GetQuarter(); var listMonth = (from Quart in DB.Quarter where Quart.Quarter == quarter select new { Quart.Month }).ToList(); string month1 = DateTime.Now.ToString("yyyy/" + listMonth[0].Month + "/01"); string month2 = DateTime.Now.ToString("yyyy/" + listMonth[1].Month + "/01"); string month3 = DateTime.Now.ToString("yyyy/" + listMonth[2].Month + "/01"); int currentmonth = GetQuarter() == quarter ? DateTime.Now.Month : Convert.ToInt32(listMonth[2].Month); List <KeyValuePair <string, string> > emailStatus = new List <KeyValuePair <string, string> >(); if (MODEL != null && ModelState.IsValid) { foreach (NewEntryByProjectSelection product in MODEL) { int _currentNumber = 0; IQueryable <int> items = DB.EmpTimeSheet.OrderByDescending(u => u.SequenceNo).Take(1).Select(e => e.SequenceNo); foreach (int ir in items) { _currentNumber = ir; } if (_currentNumber == 0) { _currentNumber = 100; } else { _currentNumber++; } if (currentmonth == Convert.ToInt32(listMonth[0].Month)) { NewEntryModel newEntryModel = new NewEntryModel(); newEntryModel.InvolveMonth = Convert.ToDateTime(month1); newEntryModel.DaysCount = Convert.ToDecimal(product.InvolvementDays1); newEntryModel.DaysEditCount = Convert.ToDecimal(product.InvolvementEditDays1); newEntryModel.InvolvePercent = CalculateInvolvementPercentage(product.EmployeeID, product.InvolvementEditDays1, newEntryModel); NewEntryModel exists = DB.EmpTimeSheet.FirstOrDefault(x => x.InvolveMonth == newEntryModel.InvolveMonth && x.EmpId == product.EmployeeID && x.ProjectID == product.ProjectID); if (exists != null) { newEntryModel.TsID = exists.TsID; newEntryModel.RefNo = exists.RefNo; newEntryModel.SequenceNo = exists.SequenceNo; newEntryModel.EntryBy = (long)Session[Constants.SessionEmpID]; //empid newEntryModel.EntryDate = DateTime.Now; newEntryModel.Quart = quarter; newEntryModel.EntryRole = (long)Session[Constants.SessionRoleID]; newEntryModel.EmpId = product.EmployeeID; //empid newEntryModel.ProjectID = product.ProjectID; newEntryModel.EmpRemarks = ""; newEntryModel.ApproveRejectComments = ""; newEntryModel.ApproveRejectStatus = "A"; newEntryModel.ApproveRejectUser = (long)Session[Constants.SessionEmpID]; newEntryModel.ApproveRejectDate = DateTime.Now; newEntryModel.Status = Convert.ToInt64(ReadConfig.GetValue("StatusApproved")); DB.Entry(exists).CurrentValues.SetValues(newEntryModel); DB.SaveChanges(); } else { if (newEntryModel.DaysEditCount != 0 || product.IsEdit1) { newEntryModel.RefNo = AutoGen.GetReferenceNumber(); newEntryModel.SequenceNo = _currentNumber; newEntryModel.EntryBy = _entryId; //empid newEntryModel.EntryDate = DateTime.Now; newEntryModel.EntryRole = (long)Session[Constants.SessionRoleID]; newEntryModel.EmpId = product.EmployeeID; //empid newEntryModel.ProjectID = product.ProjectID; newEntryModel.Quart = quarter; newEntryModel.EmpRemarks = ""; newEntryModel.ApproveRejectComments = ""; newEntryModel.ApproveRejectStatus = "A"; newEntryModel.ApproveRejectUser = (long)Session[Constants.SessionEmpID]; newEntryModel.ApproveRejectDate = DateTime.Now; newEntryModel.Status = Convert.ToInt64(ReadConfig.GetValue("StatusApproved")); DB.EmpTimeSheet.Add(newEntryModel); DB.SaveChanges(); } } } if (currentmonth == Convert.ToInt32(listMonth[1].Month)) { foreach (string month in months) { NewEntryModel newEntryModel = new NewEntryModel(); bool isEdit = false; if (month == months[0]) { newEntryModel.InvolveMonth = Convert.ToDateTime(month1); newEntryModel.DaysCount = Convert.ToDecimal(product.InvolvementDays1); newEntryModel.DaysEditCount = Convert.ToDecimal(product.InvolvementEditDays1); newEntryModel.InvolvePercent = CalculateInvolvementPercentage(product.EmployeeID, product.InvolvementEditDays1, newEntryModel); isEdit = product.IsEdit1; } if (month == months[1]) { newEntryModel.InvolveMonth = Convert.ToDateTime(month2); newEntryModel.DaysCount = Convert.ToDecimal(product.InvolvementDays2); newEntryModel.DaysEditCount = Convert.ToDecimal(product.InvolvementEditDays2); newEntryModel.InvolvePercent = CalculateInvolvementPercentage(product.EmployeeID, product.InvolvementEditDays2, newEntryModel); isEdit = product.IsEdit2; } if (newEntryModel.DaysEditCount != 0 || isEdit) { NewEntryModel exists = DB.EmpTimeSheet.FirstOrDefault(x => x.InvolveMonth == newEntryModel.InvolveMonth && x.EmpId == product.EmployeeID && x.ProjectID == product.ProjectID); if (ModelState.IsValid) { if (exists != null) { newEntryModel.TsID = exists.TsID; newEntryModel.RefNo = exists.RefNo; newEntryModel.SequenceNo = exists.SequenceNo; newEntryModel.EntryBy = (long)Session[Constants.SessionEmpID]; //empid newEntryModel.EntryDate = DateTime.Now; newEntryModel.Quart = quarter; newEntryModel.EntryRole = (long)Session[Constants.SessionRoleID]; newEntryModel.EmpId = product.EmployeeID; //empid newEntryModel.ProjectID = product.ProjectID; newEntryModel.EmpRemarks = ""; newEntryModel.ApproveRejectComments = ""; newEntryModel.ApproveRejectStatus = "A"; newEntryModel.ApproveRejectUser = (long)Session[Constants.SessionEmpID]; newEntryModel.ApproveRejectDate = DateTime.Now; newEntryModel.Status = Convert.ToInt64(ReadConfig.GetValue("StatusApproved")); DB.Entry(exists).CurrentValues.SetValues(newEntryModel); DB.SaveChanges(); } else { newEntryModel.RefNo = AutoGen.GetReferenceNumber(); newEntryModel.SequenceNo = _currentNumber; newEntryModel.EntryBy = _entryId; //empid newEntryModel.EntryDate = DateTime.Now; newEntryModel.EntryRole = (long)Session[Constants.SessionRoleID]; newEntryModel.EmpId = product.EmployeeID; //empid newEntryModel.ProjectID = product.ProjectID; newEntryModel.Quart = quarter; newEntryModel.EmpRemarks = ""; newEntryModel.ApproveRejectComments = ""; newEntryModel.ApproveRejectStatus = "A"; newEntryModel.ApproveRejectUser = (long)Session[Constants.SessionEmpID]; newEntryModel.ApproveRejectDate = DateTime.Now; newEntryModel.Status = Convert.ToInt64(ReadConfig.GetValue("StatusApproved")); DB.EmpTimeSheet.Add(newEntryModel); DB.SaveChanges(); } } else { TempData["Error"] = ResourceMessage.DayscountExceed; //return View("Index", BindData(model.QID)); } } } } if (currentmonth == Convert.ToInt32(listMonth[2].Month)) { foreach (string month in months) { NewEntryModel newEntryModel = new NewEntryModel(); bool isEdit = false; if (month == months[0]) { newEntryModel.InvolveMonth = Convert.ToDateTime(month1); newEntryModel.DaysCount = Convert.ToDecimal(product.InvolvementDays1); newEntryModel.DaysEditCount = Convert.ToDecimal(product.InvolvementEditDays1); newEntryModel.InvolvePercent = CalculateInvolvementPercentage(product.EmployeeID, product.InvolvementEditDays1, newEntryModel); isEdit = product.IsEdit1; } if (month == months[1]) { newEntryModel.InvolveMonth = Convert.ToDateTime(month2); newEntryModel.DaysCount = Convert.ToDecimal(product.InvolvementDays2); newEntryModel.DaysEditCount = Convert.ToDecimal(product.InvolvementEditDays2); newEntryModel.InvolvePercent = CalculateInvolvementPercentage(product.EmployeeID, product.InvolvementEditDays2, newEntryModel); isEdit = product.IsEdit2; } if (month == months[2]) { newEntryModel.InvolveMonth = Convert.ToDateTime(month3); newEntryModel.DaysCount = Convert.ToDecimal(product.InvolvementDays3); newEntryModel.DaysEditCount = Convert.ToDecimal(product.InvolvementEditDays3); newEntryModel.InvolvePercent = CalculateInvolvementPercentage(product.EmployeeID, product.InvolvementEditDays3, newEntryModel); isEdit = product.IsEdit3; } if (newEntryModel.DaysEditCount != 0 || isEdit) { NewEntryModel exists = DB.EmpTimeSheet.FirstOrDefault(x => x.InvolveMonth == newEntryModel.InvolveMonth && x.EmpId == product.EmployeeID && x.ProjectID == product.ProjectID); if (ModelState.IsValid) { if (exists != null) { newEntryModel.TsID = exists.TsID; newEntryModel.RefNo = exists.RefNo; newEntryModel.SequenceNo = exists.SequenceNo; newEntryModel.EntryBy = (long)Session[Constants.SessionEmpID]; //empid newEntryModel.EntryDate = DateTime.Now; newEntryModel.Quart = quarter; newEntryModel.EntryRole = (long)Session[Constants.SessionRoleID]; newEntryModel.EmpId = product.EmployeeID; //empid newEntryModel.ProjectID = product.ProjectID; newEntryModel.EmpRemarks = ""; newEntryModel.ApproveRejectComments = ""; newEntryModel.ApproveRejectStatus = "A"; newEntryModel.ApproveRejectUser = (long)Session[Constants.SessionEmpID]; newEntryModel.ApproveRejectDate = DateTime.Now; newEntryModel.Status = Convert.ToInt64(ReadConfig.GetValue("StatusApproved")); DB.Entry(exists).CurrentValues.SetValues(newEntryModel); DB.SaveChanges(); } else { newEntryModel.RefNo = AutoGen.GetReferenceNumber(); newEntryModel.SequenceNo = _currentNumber; newEntryModel.EntryBy = _entryId; //empid newEntryModel.EntryDate = DateTime.Now; newEntryModel.EntryRole = (long)Session[Constants.SessionRoleID]; newEntryModel.EmpId = product.EmployeeID; //empid newEntryModel.ProjectID = product.ProjectID; newEntryModel.Quart = quarter; newEntryModel.EmpRemarks = ""; newEntryModel.ApproveRejectComments = ""; newEntryModel.ApproveRejectStatus = "A"; newEntryModel.ApproveRejectUser = (long)Session[Constants.SessionEmpID]; newEntryModel.ApproveRejectDate = DateTime.Now; newEntryModel.Status = Convert.ToInt64(ReadConfig.GetValue("StatusApproved")); DB.EmpTimeSheet.Add(newEntryModel); DB.SaveChanges(); } } else { TempData["Error"] = ResourceMessage.DayscountExceed; //return View("Index", BindData(model.QID)); } } } } if ((product.IsEdit1 && product.InvolvementEditDays1 > 0) || (product.IsEdit2 && product.InvolvementEditDays2 > 0) || (product.IsEdit3 && product.InvolvementEditDays3 > 0)) { var SubmittedMonths = new List <string>(); if (product.IsEdit1 && product.InvolvementEditDays1 > 0) { SubmittedMonths.Add(product.Month1 + " " + Convert.ToDateTime(month1).Year); } if (product.IsEdit2 && product.InvolvementEditDays2 > 0) { SubmittedMonths.Add(product.Month2 + " " + Convert.ToDateTime(month2).Year); } if (product.IsEdit3 && product.InvolvementEditDays3 > 0) { SubmittedMonths.Add(product.Month3 + " " + Convert.ToDateTime(month3).Year); } string projectName = DB.ProjectMaster.FirstOrDefault(x => x.ProjectID == product.ProjectID).ProjectName; var projectManagers = (from x in DB.ProjectEmployee.Where(x => x.ProjectID == product.ProjectID && x.EmployeeID != product.EmployeeID && x.CheckRole) join y in DB.Employee on x.EmployeeID equals y.EmployeeID join z in DB.User on y.UserID equals z.UserID select new { z.Email, y.EmpFirstName, y.EmpLastName, y.EmpMiddleName }).ToList <dynamic>(); if (SubmittedMonths.Any() && projectManagers.Any()) { var emp = DB.Employee.FirstOrDefault(x => x.EmployeeID == product.EmployeeID); var emailObj = new TimeSheetSubmissionEmailModel() { EmpName = Models.Common.GetName(emp.EmpFirstName, emp.EmpLastName, emp.EmpMiddleName), ManagerInfo = projectManagers, ProjectName = projectName, SubmissionDates = string.Join(", ", SubmittedMonths) }; bool emailResult = await Email.SendTimeSubmissionEmail(emailObj); if (!emailResult) { emailStatus.Add(new KeyValuePair <string, string>(emailObj.EmpName, projectName)); } } } } } return(Json(new { MODEL, emailStatus })); } catch (Exception ex) { LogHelper.ErrorLog(ex); throw ex; } } else { ViewBag.Quadrent = GetQuardrent(); long empId = (long)Session[Constants.SessionEmpID]; ViewBag.QuarterList = DropdownList.PreviousAndQuarterListNewEntryOnBehalf(empId); NewEntryByProjectSelection model = new NewEntryByProjectSelection { Quarter = ViewBag.Quadrent, Month1 = "Jan-2019" }; return(View("Index", model)); } }
public void Login() { if (!Request.IsAuthenticated) { HttpContext.GetOwinContext() .Authentication.Challenge(new AuthenticationProperties { RedirectUri = redirectUri }, OpenIdConnectAuthenticationDefaults.AuthenticationType); } else { try { UserModel userExists = DB.User.Where(x => x.Email == User.Identity.Name).FirstOrDefault(); if (userExists != null) { if (userExists.IsActive) { var role = DB.Role.Join(DB.User, x => x.RoleID, y => y.RoleID, (x, y) => new { x.RoleName, x.RoleID }).Where(z => z.RoleID == userExists.RoleID).FirstOrDefault(); if (role != null) { FormsAuthenticationTicket frmAuthTicket = new FormsAuthenticationTicket(User.Identity.Name, true, Global.G_SessionTimeout); string encTicket = FormsAuthentication.Encrypt(frmAuthTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket) { Expires = DateTime.Now.AddMonths(1), HttpOnly = true }; Response.Cookies.Add(faCookie); //EmployeeModel empDetails = DB.Employee.Where(x => x.UserID == userExists.UserID).FirstOrDefault(); //employee model //if (empDetails != null) //{ // Session[Constants.SessionEmpID] = empDetails.EmployeeID; //empdetails.empid // Session[Constants.SessionEmpName] = empDetails.EmpFirstName + " " + empDetails.EmpLastName; // Employee Name //} // var empDetails = DB.Employee.Where(x => x.UserID == userDetails.UserID).FirstOrDefault(); //employee model var empDetails = (from x in DB.Employee where x.UserID == userExists.UserID select new { x.EmployeeID, Name = (x.EmpFirstName ?? "") + " " + (x.EmpMiddleName ?? "") + " " + (x.EmpLastName ?? "") }).FirstOrDefault(); if (empDetails != null) { Session[Constants.SessionEmpID] = empDetails.EmployeeID; Session[Constants.SessionEmpName] = empDetails.Name; } Session[Constants.SessionUserID] = userExists.UserID; Session[Constants.SessionRoleID] = userExists.RoleID; if (userExists.RoleID == Convert.ToInt64(ReadConfig.GetValue("RoleEmployee"))) { } else if (userExists.RoleID == Convert.ToInt64(ReadConfig.GetValue("RolePM"))) { } else if (userExists.RoleID == Convert.ToInt64(ReadConfig.GetValue("RoleAdmin"))) { } else if (userExists.RoleID == Convert.ToInt64(ReadConfig.GetValue("RoleFinance"))) { } } else { ViewBag.ErrorMsg = ResourceMessage.NoRole; //return View("Index"); } } else { ViewBag.ErrorMsg = ResourceMessage.NotActive; // return View("Index"); } } else { ViewBag.ErrorMsg = ResourceMessage.InvalidUser; //return View("Index"); } } catch (Exception ex) { LogHelper.ErrorLog(ex); } } // return RedirectToAction("Index"); }
// GET: Login public ActionResult Index() { try { if (Request.IsAuthenticated) { //HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; //if (authCookie != null) //{ // FormsAuthenticationTicket decTicket = FormsAuthentication.Decrypt(authCookie.Value); var res = (from x in DB.User join y in DB.Employee on x.UserID equals y.UserID where x.Email == User.Identity.Name select new { x.RoleID, x.UserID, y.EmployeeID, Name = (y.EmpFirstName ?? "") + " " + (y.EmpMiddleName ?? "") + " " + (y.EmpLastName ?? "") }).FirstOrDefault(); if (res != null) { Session[Constants.SessionEmpID] = res.EmployeeID; //empdetails.empid Session[Constants.SessionEmpName] = res.Name; Session[Constants.SessionUserID] = res.UserID; Session[Constants.SessionRoleID] = res.RoleID; var pageList = (from x in DB.PageMapping.Where(x => x.IsActive && x.RoleID == res.RoleID) join y in DB.Page on x.PageID equals y.PageID select y.PageName.ToLower() + "|" + Constants.Access).ToList(); Session[Constants.SessionPageAccess] = pageList; } string defaultPage = "NewEntry"; if ((long)Session[Constants.SessionRoleID] == Convert.ToInt64(ReadConfig.GetValue("RoleEmployee"))) { defaultPage = "EmployeeDashboard"; } else if ((long)Session[Constants.SessionRoleID] == Convert.ToInt64(ReadConfig.GetValue("RolePM"))) { defaultPage = "ManagerDashboard"; } else if ((long)Session[Constants.SessionRoleID] == Convert.ToInt64(ReadConfig.GetValue("RoleAdmin"))) { defaultPage = "AdminDashboard"; } else if ((long)Session[Constants.SessionRoleID] == Convert.ToInt64(ReadConfig.GetValue("RoleFinance"))) { defaultPage = "AdminTimeSheetLock"; } return(RedirectToAction("Index", defaultPage)); //} } } catch (Exception ex) { LogHelper.ErrorLog(ex); } return(View()); }
public async Task <ActionResult> Submit(NewEntryBox model) { long _empId = (long)Session[Constants.SessionEmpID]; string _empName = Session[Constants.SessionEmpName].ToString(); List <string> emailStatus = new List <string>(); try { decimal edit1 = 0; decimal edit2 = 0; decimal edit3 = 0; model.Items[model.Items.Count - 1].InvolvementEditDays1 = 0; model.Items[model.Items.Count - 1].InvolvementEditDays2 = 0; model.Items[model.Items.Count - 1].InvolvementEditDays3 = 0; for (int i = 0; i < model.Items.Count - 1; i++) { edit1 = edit1 + model.Items[i].InvolvementEditDays1; edit2 = edit2 + model.Items[i].InvolvementEditDays2; edit3 = edit3 + model.Items[i].InvolvementEditDays3; } model.Items[model.Items.Count - 1].InvolvementEditDays1 = edit1; model.Items[model.Items.Count - 1].InvolvementEditDays2 = edit2; model.Items[model.Items.Count - 1].InvolvementEditDays3 = edit3; if (Convert.ToDouble(model.Items[model.Items.Count - 1].InvolvementDays1) < Convert.ToDouble(model.Items[model.Items.Count - 1].InvolvementEditDays1) || Convert.ToDouble(model.Items[model.Items.Count - 1].InvolvementDays2) < Convert.ToDouble(model.Items[model.Items.Count - 1].InvolvementEditDays2) || Convert.ToDouble(model.Items[model.Items.Count - 1].InvolvementDays3) < Convert.ToDouble(model.Items[model.Items.Count - 1].InvolvementEditDays3)) { ViewBag.ErrorMessage = "Total Input is more than allowable days, Please adjust your timesheet"; ViewBag.QuarterList = model.QID; ViewBag.QuarterList = DropdownList.PreviousAndQuarterList(_empId, true); return(View("Index", BindData(model.QID))); } if (model != null) { int roleId = Convert.ToInt32(Session[Constants.SessionRoleID]); foreach (BoxItems item in model.Items.Where(x => x.IsEdit1 || x.IsEdit2 || x.IsEdit3)) { if (item.ProjectID != 0) { int _currentNumber = 0; IQueryable <int> items = DB.EmpTimeSheet.OrderByDescending(u => u.SequenceNo).Take(1).Select(e => e.SequenceNo); foreach (int ir in items) { _currentNumber = ir; } if (_currentNumber == 0) { _currentNumber = 100; } else { _currentNumber++; } foreach (string month in months) { bool isEditable = false; NewEntryModel newEntryModel = new NewEntryModel(); newEntryModel.ApproveRejectStatus = roleId == 1 ? "A" : DB.ProjectEmployee.FirstOrDefault(x => x.EmployeeID == _empId && x.ProjectID == item.ProjectID).CheckRole == true ? "A" : null; if (month == months[0]) { newEntryModel.InvolveMonth = Convert.ToDateTime(model.Month1); newEntryModel.DaysCount = item.InvolvementDays1; newEntryModel.DaysEditCount = item.InvolvementEditDays1; newEntryModel.InvolvePercent = CalculateInvolvementPercentage(_empId, item.InvolvementEditDays1, newEntryModel); if (item.IsEdit1) { isEditable = true; } } if (month == months[1]) { newEntryModel.InvolveMonth = Convert.ToDateTime(model.Month2); newEntryModel.DaysCount = item.InvolvementDays2; newEntryModel.DaysEditCount = item.InvolvementEditDays2; newEntryModel.InvolvePercent = CalculateInvolvementPercentage(_empId, item.InvolvementEditDays2, newEntryModel); if (item.IsEdit2) { isEditable = true; } } if (month == months[2]) { newEntryModel.InvolveMonth = Convert.ToDateTime(model.Month3); newEntryModel.DaysCount = item.InvolvementDays3; newEntryModel.DaysEditCount = item.InvolvementEditDays3; newEntryModel.InvolvePercent = CalculateInvolvementPercentage(_empId, item.InvolvementEditDays3, newEntryModel); if (item.IsEdit3) { isEditable = true; } } if (newEntryModel.DaysCount != 0) { if (isEditable) { NewEntryModel exists = DB.EmpTimeSheet.FirstOrDefault(x => x.InvolveMonth == newEntryModel.InvolveMonth && x.EmpId == _empId && x.ProjectID == item.ProjectID); if (exists != null) { newEntryModel.TsID = exists.TsID; newEntryModel.RefNo = exists.RefNo; newEntryModel.SequenceNo = exists.SequenceNo; newEntryModel.EntryBy = _empId; //empid newEntryModel.EntryDate = DateTime.Now; newEntryModel.Quart = model.QID; newEntryModel.EntryRole = (long)Session[Constants.SessionRoleID]; newEntryModel.EmpId = _empId; //empid newEntryModel.ProjectID = item.ProjectID; newEntryModel.EmpRemarks = ""; newEntryModel.Status = newEntryModel.ApproveRejectStatus == "A" ? Convert.ToInt64(ReadConfig.GetValue("StatusApproved")) : Convert.ToInt64(ReadConfig.GetValue("StatusPending")); if (newEntryModel.ApproveRejectStatus == "A") { newEntryModel.ApproveRejectUser = _empId; } DB.Entry(exists).CurrentValues.SetValues(newEntryModel); } else { newEntryModel.RefNo = AutoGen.GetReferenceNumber(); newEntryModel.SequenceNo = _currentNumber; newEntryModel.EntryBy = _empId; //empid newEntryModel.EntryDate = DateTime.Now; newEntryModel.Quart = model.QID; newEntryModel.EntryRole = (long)Session[Constants.SessionRoleID]; newEntryModel.EmpId = _empId; //empid newEntryModel.ProjectID = item.ProjectID; newEntryModel.EmpRemarks = ""; newEntryModel.Status = newEntryModel.ApproveRejectStatus == "A" ? Convert.ToInt64(ReadConfig.GetValue("StatusApproved")) : Convert.ToInt64(ReadConfig.GetValue("StatusPending")); if (newEntryModel.ApproveRejectStatus == "A") { newEntryModel.ApproveRejectUser = _empId; } DB.EmpTimeSheet.Add(newEntryModel); } DB.SaveChanges(); if (newEntryModel.Status == Convert.ToInt64(ReadConfig.GetValue("StatusApproved"))) { TempData["Success"] = ResourceMessage.NewEntryApprove; } else if (newEntryModel.Status == Convert.ToInt64(ReadConfig.GetValue("StatusPending"))) { TempData["Success"] = ResourceMessage.NewEntrySubmit; } } } } if ((item.InvolvementDays1 > 0 && item.InvolvementEditDays1 > 0) || (item.InvolvementDays2 > 0 && item.InvolvementEditDays2 > 0) || (item.InvolvementDays3 > 0 && item.InvolvementEditDays3 > 0)) { var SubmittedMonths = new List <string>(); if (item.IsEdit1 && item.InvolvementEditDays1 > 0) { SubmittedMonths.Add(model.Month1); } if (item.IsEdit2 && item.InvolvementEditDays2 > 0) { SubmittedMonths.Add(model.Month2); } if (item.IsEdit3 && item.InvolvementEditDays3 > 0) { SubmittedMonths.Add(model.Month3); } if (roleId != 1) { bool isProjectManager = DB.ProjectEmployee.FirstOrDefault(x => x.ProjectID == item.ProjectID && x.EmployeeID == _empId).CheckRole; if (!isProjectManager) { string projectName = DB.ProjectMaster.FirstOrDefault(x => x.ProjectID == item.ProjectID).ProjectName; var projectManagers = (from x in DB.ProjectEmployee.Where(x => x.ProjectID == item.ProjectID && x.EmployeeID != _empId && x.CheckRole) join y in DB.Employee on x.EmployeeID equals y.EmployeeID join z in DB.User on y.UserID equals z.UserID select new { z.Email, y.EmpFirstName, y.EmpLastName, y.EmpMiddleName }).ToList <dynamic>(); if (SubmittedMonths.Any() && projectManagers.Any()) { bool emailResult = await Email.SendTimeSubmissionEmail(new TimeSheetSubmissionEmailModel() { EmpName = _empName, ManagerInfo = projectManagers, ProjectName = projectName, SubmissionDates = string.Join(", ", SubmittedMonths) }); if (!emailResult) { emailStatus.Add(projectName); } } } } } } } } } catch (Exception ex) { TempData["Error"] = ex.ToString(); LogHelper.ErrorLog(ex); } // TempData["EmailNotificationErrors"] = emailStatus; return(RedirectToAction("Index")); }