コード例 #1
0
        internal static async Task UpdateCandidateTimesheet(tblCandidateTimesheet model)
        {
            try
            {
                using (db = new eMSPEntities())
                {
                    var existingParent = db.tblCandidateTimesheets
                                         .Where(p => p.ID == model.ID)
                                         .Include(p => p.tblCandidateTimesheetHours)
                                         .SingleOrDefault();

                    if (existingParent != null)
                    {
                        db.Entry(existingParent).CurrentValues.SetValues(model);

                        foreach (var existingChild in existingParent.tblCandidateTimesheetHours.ToList())
                        {
                            if (!model.tblCandidateTimesheetHours.Any(c => c.ID == existingChild.ID))
                            {
                                db.tblCandidateTimesheetHours.Remove(existingChild);
                            }
                        }

                        foreach (var childModel in model.tblCandidateTimesheetHours)
                        {
                            var existingChild = existingParent.tblCandidateTimesheetHours
                                                .Where(c => c.ID == childModel.ID)
                                                .SingleOrDefault();

                            if (existingChild != null)
                            {
                                db.Entry(existingChild).CurrentValues.SetValues(childModel);
                            }
                            else
                            {
                                existingParent.tblCandidateTimesheetHours.Add(childModel);
                            }
                        }

                        int x = await Task.Run(() => db.SaveChangesAsync());
                    }
                    else
                    {
                        await Task.Run(() => InsertCandidateTimesheet(model));
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #2
0
        public async Task <CandidateTimesheetViewModel> CreateCandidateTimesheet(CandidateTimesheetViewModel data)
        {
            try
            {
                tblCandidateTimesheet res = await Task.Run(() => ManageCandidateTimesheets.InsertCandidateTimesheet(data.ConvertTotblCandidateTimesheet()));

                return(res.ConvertToCandidateTimesheetViewModel());
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        public async Task <CandidateTimesheetViewModel> GetTimesheetDetailsById(long TimesheetId)
        {
            try
            {
                tblCandidateTimesheet res = await Task.Run(() => ManageCandidateTimesheets.GetTimesheetDetailsById(TimesheetId));

                return(res.ConvertToCandidateTimesheetViewModel());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #4
0
        public async Task <CandidateTimesheetViewModel> GetCandidateTimesheetDetails(long placementId, long payPeriodId)
        {
            try
            {
                tblCandidateTimesheet res = await Task.Run(() => ManageCandidateTimesheets.GetCandidateTimesheet(placementId, payPeriodId));

                return(res.ConvertToCandidateTimesheetViewModel());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #5
0
        internal static async Task <tblCandidateTimesheet> InsertCandidateTimesheet(tblCandidateTimesheet model)
        {
            try
            {
                using (db = new eMSPEntities())
                {
                    var candidateTimesheet = db.tblCandidateTimesheets.Add(model);
                    int x = await Task.Run(() => db.SaveChangesAsync());

                    return(candidateTimesheet);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #6
0
 public static CandidateTimesheetViewModel ConvertToCandidateTimesheetViewModel(this tblCandidateTimesheet data)
 {
     if (data == null)
     {
         return(null);
     }
     else
     {
         return(new CandidateTimesheetViewModel()
         {
             ID = Convert.ToInt64(data.ID),
             PayPeriodID = data.PayPeriodID,
             PlacementID = data.PlacementID,
             StatusID = data.StatusID,
             VersionNumber = data.VersionNumber,
             isActive = data.IsActive,
             isDeleted = data.IsDeleted ?? false,
             createdUserID = data.CreatedUserID,
             updatedUserID = data.UpdatedUserID,
             createdTimestamp = data.CreatedTimestamp,
             updatedTimestamp = data.UpdatedTimestamp,
             CandidateTimesheetHours = data.tblCandidateTimesheetHours.Select(x => x?.ConvertToCandidateTimesheetHoursViewModel()).ToList(),
             CandidateTimesheetCategoriesHours = data.tblCandidateTimesheetCategoriesHours.Select(x => x?.ConvertToCandidateTimesheetCategoriesHoursViewModel()).ToList(),
             CandidatePlacement = data.tblCandidatePlacement?.ConvertToCandidatePlacementViewModel(),
             MSPPayPeriods = data.tblMSPPayPeriod?.ConvertToMSPPayPeriodViewModel(),
             TimesheetStatus = data.tblTimesheetStatu?.ConvertToTimesheetStatusViewModel()
         });
     }
 }