Exemplo n.º 1
0
        public JsonResult GetGrantLeaves()
        {
            JsonResult result = null;

            try
            {
                List <LeaveHeader>          leaveHeaders      = GrantLeaveService.GetAll <LeaveHeader>().ToList();
                List <LeaveHeaderViewModel> LeaveHeaderVMList = new List <LeaveHeaderViewModel>();
                List <LookUp> LeaveTypeLookUp = LookUpCodeService.GetLookUp <LookUp>(l => l.LookUpCategory == "LeaveType").ToList();
                foreach (LeaveHeader leaveHeader in leaveHeaders)
                {
                    LeaveHeaderViewModel LeaveHeaderVM = new LeaveHeaderViewModel()
                    {
                        Id                         = leaveHeader.Id,
                        BranchId                   = leaveHeader.BranchID,
                        LeaveSchemeType            = leaveHeader.LeaveSchemeType,
                        LeaveSchemeTypeDescription = LookUpCodeService.GetLookUp <LookUp>(l => l.LookUpID == leaveHeader.LeaveSchemeType).Select(s => s.LookUpCode).FirstOrDefault(),
                        LeaveYear                  = leaveHeader.LeaveYear,
                        LeaveYearType              = LookUpCodeService.GetLookUp <LookUp>(l => l.LookUpID == leaveHeader.LeaveYear).Select(l => l.LookUpCode).FirstOrDefault(),
                        PeriodicityType            = leaveHeader.PeriodicityType,
                        PeriodicityTypeDescription = LookUpCodeService.GetLookUp <LookUp>(l => l.LookUpID == leaveHeader.PeriodicityType).Select(l => l.LookUpCode).FirstOrDefault(),
                        PeriodType                 = leaveHeader.PeriodType,
                        PeriodTypeDescription      = LookUpCodeService.GetLookUp <LookUp>(l => l.LookUpID == leaveHeader.PeriodType).Select(l => l.LookUpCode).FirstOrDefault(),
                    };
                    PrepareleavedetailsViewModel(leaveHeader, LeaveHeaderVM, LeaveTypeLookUp);
                    LeaveHeaderVMList.Add(LeaveHeaderVM);
                }
                result = Json(new { sucess = true, LeaveHeaderVMList = LeaveHeaderVMList }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    return(Json(new { success = false, message = ex.InnerException.Message }, JsonRequestBehavior.DenyGet));
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        private void PrepareleavedetailsViewModel(LeaveHeader leaveHeader, LeaveHeaderViewModel leaveHeaderVM, List <LookUp> lookUp)
        {
            if (leaveHeader.LeaveDetail != null && leaveHeader.LeaveDetail.Any())
            {
                foreach (LeaveDetail leaveDetail in leaveHeader.LeaveDetail)
                {
                    LeaveDetailViewModel leaveDetailVM = new LeaveDetailViewModel()
                    {
                        Id                   = leaveDetail.Id,
                        IsChecked            = leaveDetail.LeaveType > 0 ? true : false,
                        LeaveType            = leaveDetail.LeaveType,
                        LeaveTypeDescription = lookUp.Where(s => s.LookUpID == leaveDetail.LeaveType).Select(s => s.LookUpCode).FirstOrDefault(),
                        TotalLeaves          = leaveDetail.TotalLeaves,
                        LeaveHeaderId        = leaveDetail.LeaveHeaderId
                    };
                    if (leaveHeaderVM.LeaveDetail == null)
                    {
                        leaveHeaderVM.LeaveDetail = new List <LeaveDetailViewModel>();
                    }

                    leaveHeaderVM.LeaveDetail.Add(leaveDetailVM);
                }
            }
        }