public ActionResult Apply(ApplyForLeaveViewModel model) { BLLLeave _leave = new BLLLeave(); JsonResult json = new JsonResult(); json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; model.PeriodFrom = Convert.ToDateTime(model.PeriodFrom).ToShortDateString(); model.PeriodTo = Convert.ToDateTime(model.PeriodTo).ToShortDateString(); string result = "error"; if(_leave.Apply(User.IDNO, model)) { //Email manager BLLEmail _email = new BLLEmail(); if(_email.EmailManager(model)) { result = "success"; } } json.Data = new { result = result }; return json; }
public bool Apply(string IDNO, ApplyForLeaveViewModel model) { bool updatedLeaveCreditWithPay = true; bool apply = false; DALLeave _leave = new DALLeave(); //If leave type is VL/SL with Pay if(model.LessThisLeave != 0) { model.LessThisLeave = RoundLessThisLeave(model.LessThisLeave); updatedLeaveCreditWithPay = _leave.UpdateLeaveCreditWithPay(IDNO, model); } //Insert into dbo.Leave apply = _leave.Apply(IDNO, model); return (updatedLeaveCreditWithPay && apply); }
public bool EmailManager(ApplyForLeaveViewModel model){ bool sendSuccess = false; BLLProfile _profile = new BLLProfile(); using (SmtpClient client = new SmtpClient(SERVER, PORT)) { string EMAIL_FROM = "*****@*****.**"; string SUBJECT = "Leave of Absence Application [no-reply]"; //string EMAIL_TO = _profile.GetEmployeeProfile(model.DepartmentManagerIDNO).Email; string EMAIL_TO = "*****@*****.**"; string LINK = "http://cebapp03/EMP/Account/Login"; StringBuilder BODY = new StringBuilder(); BODY.Append("<p>" + model.EmployeeName + " has applied for Leave of Absence:</p><br>"); BODY.Append("<p><strong>Date Filed: </strong>" + model.DateFiled + "</p>"); BODY.Append("<p><strong>Type: </strong>" + new BLLLeave().GetAllLeaveTypes().Where(i => i.LOOKUPLeaveTypeID == model.LeaveTypeID).SingleOrDefault().LeaveType + "</p>"); BODY.Append("<p><strong>From: </strong>" + model.PeriodFrom + "</p>"); BODY.Append("<p><strong>To: </strong>" + model.PeriodTo + "</p>"); BODY.Append("<p><strong>Address: </strong>" + model.AddressOnLeave + "</p>"); BODY.Append("<p><strong>Reason: </strong>" + model.Reason + "</p><br>"); BODY.Append("<p>Click <a href='" + LINK + "' target='_blank'>here</a> to respond to the application on EMP.<p>"); MailMessage msg = new MailMessage(EMAIL_FROM, EMAIL_TO, SUBJECT, BODY.ToString()); msg.IsBodyHtml = true; try { client.Send(msg); sendSuccess = true; } catch (Exception e) { sendSuccess = false; Debug.WriteLine(e); } } return sendSuccess; }
/* * Updates leave credit for Vacation/Sick Leaves with Pay. * Revise if other leave types attain leave credit. * */ public bool UpdateLeaveCreditWithPay(string IDNO, ApplyForLeaveViewModel model) { using(DataContext _context = new DataContext()) { int _affectedRows = _context.Database.ExecuteSqlCommand("pUpdateLeaveCreditWithPay @xIDNO, @xLOOKUPLeaveTypeID, @xLessThisLeave", new SqlParameter("@xIDNO", 10001), new SqlParameter("@xLOOKUPLeaveTypeID", model.LeaveTypeID), new SqlParameter("@xLessThisLeave", model.LessThisLeave)); _context.Database.Connection.Close(); _context.Database.Connection.Dispose(); if(_affectedRows == 1) { return true; } } return false; }
public bool Apply(string IDNO, ApplyForLeaveViewModel model) { using(DataContext _context = new DataContext()) { var _rowsAffected = _context.Database.ExecuteSqlCommand("pInsertLeave @xIDNO, @xDepartmentManagerIDNO, @xDateFiled, @xLOOKUPLeaveTypeID, " + "@xDateOfLeaveFrom, @xDateOfLeaveTo, @xDurationInDays, @xDurationInHours, " + "@xAddress, @xReason", new SqlParameter("@xIDNO", IDNO), new SqlParameter("@xDepartmentManagerIDNO", model.DepartmentManagerIDNO), new SqlParameter("@xDateFiled", model.DateFiled), new SqlParameter("@xLOOKUPLeaveTypeID", model.LeaveTypeID), new SqlParameter("@xDateOfLeaveFrom", model.PeriodFrom), new SqlParameter("@xDateOfLeaveTo", model.PeriodTo), new SqlParameter("@xDurationInDays", model.NumberOfDays), new SqlParameter("@xDurationInHours", model.NumberOfHours), new SqlParameter("@xAddress", model.AddressOnLeave), new SqlParameter("@xReason", model.Reason)); _context.Database.Connection.Close(); _context.Database.Connection.Dispose(); return (_rowsAffected == 2) ? true : false; } }