コード例 #1
0
 public bool UpdateLOA(LOA loa)
 {
     using (var _context = new AdminPortalEntities())
     {
         _context.LOAs.Attach(loa);
         _context.Entry(loa).State = EntityState.Modified;
         _context.SaveChanges();
         return(true);
     }
 }
コード例 #2
0
        public ActionResult EmployeeManagerLOADownload(int id)
        {
            try
            {
                LoaViewModel lvm        = new LoaViewModel();
                LOAService   loaService = new LOAService();

                var loa = new LOA();


                loa = loaService.GetLOA(id);


                if (loa == null)
                {
                    TempData["error"] = "Either this file does not exist or you dont have permissions";
                    return(RedirectToAction("EmployeeManagerLOAList"));
                }

                lvm = Mapper.Map <LOA, LoaViewModel>(loa);

                lvm.TimeOfDayList          = GetDropDownList("LoaTimeOfDay", null);
                lvm.TypeOfLeaveList        = GetDropDownList("LoaTypeOfLeave", null);
                lvm.LookupOtherTimeOfDay   = loaService.GetLookupIdForCodeName("Other", "LoaTimeOfDay").LookupCodeId;
                lvm.LookupOtherTypeOfLeave = loaService.GetLookupIdForCodeName("Other", "LoaTypeOfLeave").LookupCodeId;

                //var typeOfleaveDDL = new SelectList(lvm.TypeOfLeaveList, "Id", "Name");
                if (lvm.LookupTypeOfLeave != lvm.LookupOtherTypeOfLeave)
                {
                    var leaveType = lvm.TypeOfLeaveList.Where(x => x.Id == lvm.LookupTypeOfLeave).First().Name;
                    lvm.OtherTypeOfLeave = leaveType;
                }
                if (lvm.LookupTimeOfDay != lvm.LookupOtherTimeOfDay)
                {
                    var timeOfDay = lvm.TimeOfDayList.Where(x => x.Id == lvm.LookupTimeOfDay).First().Name;
                    lvm.OtherTimeOfDay = timeOfDay;
                }

                if (lvm.AspNetUser.AspNetUser1 != null)
                {
                    lvm.ReportingManager = lvm.AspNetUser.AspNetUser1.Firstname + " " + lvm.AspNetUser.AspNetUser1.LastName;
                }
                else
                {
                    lvm.ReportingManager = "None";
                }

                return(PartialView("_DownloadLOAView", lvm));
            }
            catch (Exception ex)
            {
                TempData["error"] = "Something went wrong while downloading";
                return(RedirectToAction("EmployeeManagerLOAList"));
            }
        }
コード例 #3
0
 public bool CreateLoa(LOA loa)
 {
     using (var _context = new AdminPortalEntities())
     {
         _context.LOAs.Add(loa);
         _context.SaveChanges();
         loa.LoaCode = "LOA" + (1100 + loa.LoaId).ToString();
         _context.LOAs.Attach(loa);
         _context.Entry(loa).State = EntityState.Modified;
         _context.SaveChanges();
         return(true);
     }
 }
コード例 #4
0
 public LOA GetLOA(int id, string userId = null)
 {
     using (var _context = new AdminPortalEntities())
     {
         var loa = new LOA();
         if (userId != null)
         {
             loa = _context.LOAs.Where(x => x.LoaId == id && x.AspNetUser.AspNetUser1.Id == userId).Include(x => x.AspNetUser).Include(x => x.AspNetUser.AspNetUser1).Include(x => x.LookupCodeMaster).Include(x => x.LookupCodeMaster1).Include(x => x.LookupCodeMaster2).FirstOrDefault();
         }
         else
         {
             loa = _context.LOAs.Where(x => x.LoaId == id).Include(x => x.AspNetUser).Include(x => x.AspNetUser.AspNetUser1).Include(x => x.LookupCodeMaster).Include(x => x.LookupCodeMaster1).Include(x => x.LookupCodeMaster2).FirstOrDefault();
         }
         return(loa);
     }
 }
コード例 #5
0
        public async Task <ActionResult> MyLOACreate([Bind(Exclude = "LookupLoaStatus,LoaCode")] LoaViewModel lvm, string action)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    lvm.TimeOfDayList   = GetDropDownList("LoaTimeOfDay", null);
                    lvm.TypeOfLeaveList = GetDropDownList("LoaTypeOfLeave", null);
                    return(View(lvm));
                }
                //else if(tsvm.TotalHours <= 0 || tsvm.TotalHours == null)
                //{
                //    ModelState.AddModelError("error", "Total Hours cannot be less than or equal to 0");
                //    tsvm.AbsenceTypeList = GetDropDownList("Absence", null);
                //    return View(tsvm);
                //}

                LOA        loa        = new LOA();
                LOAService loaService = new LOAService();

                loa = Mapper.Map <LoaViewModel, LOA>(lvm);


                //loa.UserId = lvm.UserId;
                //loa.StartDate = lvm.StartDate;
                //loa.EndDate = lvm.EndDate;
                loa.AspNetUser = null;
                UserService userService = new UserService();
                var         user        = userService.GetUserWithId(lvm.UserId);
                var         repoMan     = user.AspNetUser1;


                loa.IsActive        = true;
                loa.IsDeleted       = false;
                loa.CreatedUserId   = User.Identity.GetUserId();
                loa.CreatedDate     = DateTime.Now;
                loa.ModifiedUserId  = User.Identity.GetUserId();
                loa.ModifiedDate    = DateTime.Now;
                loa.LookupLoaStatus = loaService.GetLookupIdForCodeName("Saved", "LoaStatus").LookupCodeId;


                loaService.CreateLoa(loa);


                if (string.Equals(action.ToString(), "Submit"))
                {
                    if (repoMan != null)
                    {
                        ChangeStatusOfLOA(loa.LoaId, "Pending");
                        await SendEmailLOASubmitted(loa.LoaId);

                        TempData["status"] = "LOA " + loa.LoaCode + " successfully saved and submitted to your reporting manager";
                    }

                    else
                    {
                        TempData["status"] = "Your LOA is saved but not submitted. You do not have a reporting manager assigned. Please contact your admin.";
                    }
                }


                return(RedirectToAction("MyLOAList"));
            }


            catch (Exception ex)
            {
                LOAService loaService = new LOAService();
                lvm.TimeOfDayList          = GetDropDownList("LoaTimeOfDay", null);
                lvm.TypeOfLeaveList        = GetDropDownList("LoaTypeOfLeave", null);
                TempData["error"]          = "Something went wrong while saving LOA";
                lvm.LookupOtherTimeOfDay   = loaService.GetLookupIdForCodeName("Other", "LoaTimeOfDay").LookupCodeId;
                lvm.LookupOtherTypeOfLeave = loaService.GetLookupIdForCodeName("Other", "LoaTypeOfLeave").LookupCodeId;
                return(RedirectToAction("MyLOAList"));
            }
        }
コード例 #6
0
        private string GetDocFileName(LOA loa)
        {
            string fileName = loa.AspNetUser.Firstname + loa.AspNetUser.LastName + "-LOA" + loa.EndDate.ToString("MMddyy") + ".pdf";

            return(fileName);
        }