Esempio n. 1
0
        public IActionResult DeleteByTempID(int TempCardId)
        {
            // Grab the entry from the temp table. "Delete" entry by making an entry in the temp table with the same data and
            // setting Delete to true
            var tempcard = context.TblTempTimecards.Find(TempCardId);

            TblTempTimecards deleteEntry = new TblTempTimecards
            {
                TimeId       = tempcard.TimeId,
                EmployeeId   = tempcard.EmployeeId,
                TimePeriodId = (int)tempcard.TimePeriodId,
                TimeDate     = tempcard.TimeDate,
                ProjectId    = tempcard.ProjectId,
                SpecId       = tempcard.SpecId,
                HourType     = tempcard.HourType,
                HourTime     = tempcard.HourTime,
                EditedDate   = DateTime.UtcNow,
                OnRoad       = tempcard.OnRoad,
                Add          = false,
                Edit         = false,
                Delete       = true
            };

            context.Add(deleteEntry);
            context.SaveChanges();


            return(RedirectToAction("Index", new { actionDone = "delete" }));
        }
Esempio n. 2
0
        public IActionResult DeleteByTimeID(int TimeId)
        {
            // Grab the entry from the live table. "Delete" entry by making an entry in the temp table with the same data and
            // setting Delete to true
            var timecard = context.TblTimecards.Include(tc => tc.TblSpec)
                           .Include(tc => tc.TblProjects)
                           .Include(tc => tc.HourTypeNavigation)
                           .Where(x => x.TimeId == TimeId).FirstOrDefault();

            TblTempTimecards deleteEntry = new TblTempTimecards
            {
                TimeId       = timecard.TimeId,
                EmployeeId   = timecard.EmployeeId,
                TimePeriodId = (int)timecard.TimePeriodId,
                TimeDate     = timecard.TimeDate,
                ProjectId    = timecard.ProjectId,
                SpecId       = timecard.SpecId,
                HourType     = timecard.HourType,
                HourTime     = timecard.HourTime,
                EditedDate   = DateTime.UtcNow,
                OnRoad       = false,
                Add          = false,
                Edit         = false,
                Delete       = true
            };

            context.Add(deleteEntry);
            context.SaveChanges();

            return(RedirectToAction("Index", new { actionDone = "delete" }));
        }
Esempio n. 3
0
 private bool Modified(TblTempTimecards timecard, TblTimecards original)
 {
     return(original.TimeDate != timecard.TimeDate ||
            original.ProjectId != timecard.ProjectId ||
            original.SpecId != timecard.SpecId ||
            original.HourType != timecard.HourType ||
            original.HourTime != timecard.HourTime);
 }
Esempio n. 4
0
        public IActionResult Save(EditViewModel editModel)
        {
            // Get the timecard from the edit VM
            TblTimecards timecard = editModel.TimeCard;

            // Check if the original entry is in the temp table - if so, grab the last updated one
            var tempcard = context.TblTempTimecards.Where(x => x.TimeId == timecard.TimeId).GroupBy(x => x.TimeId).Select(x => x.LastOrDefault()).ToList();

            bool modified = false;

            // If tempcard is empty, then the original entry is not in the temp table but in the live table
            if (tempcard.Count == 0)
            {
                var tmcard = context.TblTimecards.Find(timecard.TimeId);
                modified = Modified(tmcard, timecard);
            }
            else
            {
                // Should probably do something here if the entry for the timecard is marked for delete
                if (tempcard[0].Delete)
                {
                    return(View("Index"));
                }

                modified = Modified(tempcard[0], timecard);
            }


            // If there have been changes from what's in the database, update it and add to the temp table
            if (modified)
            {
                TblTempTimecards editToTemp = new TblTempTimecards
                {
                    EmployeeId   = 77,
                    TimeId       = timecard.TimeId,
                    TimePeriodId = (int)timecard.TimePeriodId,
                    TimeDate     = timecard.TimeDate,
                    ProjectId    = timecard.ProjectId,
                    SpecId       = timecard.SpecId,
                    HourTime     = timecard.HourTime,
                    HourType     = timecard.HourType,
                    OnRoad       = false,
                    EditedDate   = DateTime.UtcNow,
                    Edit         = true
                };

                context.TblTempTimecards.Add(editToTemp);
                context.SaveChanges();
                return(RedirectToAction("Index", new { actionDone = "edit" }));
            }


            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public IActionResult CreateNewTimeCard(EditViewModel editModel)
        {
            TblTempTimecards tempTableTimeCard = new TblTempTimecards();

            // Get current time id
            var tempLastId    = context.TblTempTimecards.Select(x => x.TimeId).LastOrDefault();
            var liveLastId    = context.TblTimecards.Select(x => x.TimeId).LastOrDefault();
            int currentTimeId = Math.Max(tempLastId, liveLastId) + 1;

            // Get current pay period id
            var activePayPeriod = context.TblTimecardHeader.Where(x => x.Validated == false).Select(x => x.TimePeriodId).FirstOrDefault();

            // Create tempTimeCard
            tempTableTimeCard.EmployeeId   = (int)HttpContext.Session.GetInt32("EmpID");
            tempTableTimeCard.TimeId       = currentTimeId;
            tempTableTimeCard.TimePeriodId = activePayPeriod;
            tempTableTimeCard.TimeDate     = editModel.TimeCard.TimeDate;
            tempTableTimeCard.ProjectId    = editModel.TimeCard.ProjectId;
            tempTableTimeCard.SpecId       = editModel.TimeCard.SpecId;
            tempTableTimeCard.HourType     = editModel.TimeCard.HourType;
            tempTableTimeCard.HourTime     = editModel.TimeCard.HourTime;
            tempTableTimeCard.CreatedDate  = DateTime.UtcNow;
            tempTableTimeCard.Add          = true;
            tempTableTimeCard.Edit         = false;
            tempTableTimeCard.Delete       = false;


            // Add tempTimeCard to database
            try
            {
                context.TblTempTimecards.Add(tempTableTimeCard);
                context.SaveChanges();
            }
            catch (Exception ex)
            {
            }

            // Return to Index view, with add confirmation box
            return(RedirectToAction("Index", new { actionDone = "add" }));
        }