public HttpResponseMessage saveShiftForStaff([FromBody] ShiftViewModel shiftDetails)
        {
            IEnumerable <StaffTimesheetsViewModel>    result             = null;
            IEnumerable <OverlappingShiftIdViewModel> overlapCheckResult = null;

            int userID            = GetCurrentUserID();
            var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
            var username          = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

            try
            {
                overlapCheckResult = _jobsService.checkForOverlappingShiftStaff(userID, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME);
                if (overlapCheckResult.Count() > 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.Conflict, "Error: shift overlap detected"));
                }
                result = _jobsService.saveShiftForStaff(userID, shiftDetails.EML, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME, shiftDetails.HOURS_WORKED, shiftDetails.HOURS_TYPE, shiftDetails.SHIFT_NOTES, username);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Esempio n. 2
0
        public async Task <ActionResult> Save(ShiftViewModel model)
        {
            using (ShiftServiceClient client = new ShiftServiceClient())
            {
                Shift obj = new Shift()
                {
                    Key         = model.Name,
                    EndTime     = model.EndTime,
                    IsOverDay   = model.IsOverDay,
                    StartTime   = model.StartTime,
                    Description = model.Description,
                    Editor      = User.Identity.Name,
                    EditTime    = DateTime.Now,
                    CreateTime  = DateTime.Now,
                    Creator     = User.Identity.Name
                };
                MethodReturnResult rst = await client.AddAsync(obj);

                if (rst.Code == 0)
                {
                    rst.Message = string.Format(FMMResources.StringResource.Shift_Save_Success
                                                , model.Name);
                }
                return(Json(rst));
            }
        }
Esempio n. 3
0
        // GET: Shifts/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var shift = await _context.Shifts
                        .SingleOrDefaultAsync(m => m.Id == id);

            if (shift == null)
            {
                return(NotFound());
            }

            var shiftViewModel = new ShiftViewModel
            {
                Shift        = shift,
                BusserTipout = _shiftService.GetTipout(shift),
                RunnerTipout = _shiftService.GetTipout(shift),
                HourlyWage   = _shiftService.GetHourlyWage(shift)
            };

            return(View(shiftViewModel));
        }
Esempio n. 4
0
        public HttpResponseMessage saveShiftForUser([FromBody] ShiftViewModel shiftDetails)
        {
            IEnumerable <StudentTimesheetsViewModel>  result             = null;
            IEnumerable <OverlappingShiftIdViewModel> overlapCheckResult = null;

            int userID            = GetCurrentUserID();
            var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
            var username          = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;

            try
            {
                if (shiftDetails.SHIFT_START_DATETIME == null || shiftDetails.SHIFT_END_DATETIME == null || shiftDetails.SHIFT_START_DATETIME == shiftDetails.SHIFT_END_DATETIME)
                {
                    _errorLogService.Log($"Invalid timesheets shift saved. Student ID: {shiftDetails.ID}, job ID: {shiftDetails.EML}, shiftStart: {shiftDetails.SHIFT_START_DATETIME}, shift end time: {shiftDetails.SHIFT_END_DATETIME}, hours worked: {shiftDetails.HOURS_WORKED} at time {DateTime.Now}");
                    throw new Exception("Invalid shift times. shiftStart and shiftEnd must be non-null and not the same.");
                }
                ;

                overlapCheckResult = _jobsService.checkForOverlappingShift(userID, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME);
                if (overlapCheckResult.Count() > 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.Conflict, "Error: shift overlap detected"));
                }
                result = _jobsService.saveShiftForUser(userID, shiftDetails.EML, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME, shiftDetails.HOURS_WORKED, shiftDetails.SHIFT_NOTES, username);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Esempio n. 5
0
        public int MapViewModelToShift(ShiftViewModel model, string user, bool performSave)
        {
            var shift = repository.GetById <IsolatorShift>(model.ShiftId);

            shift = shift == null?Mapper.Map <ShiftViewModel, IsolatorShift>(model) : Mapper.Map(model, shift);

            var st  = Convert.ToDateTime(model.StartTime);
            var end = Convert.ToDateTime(model.EndTime);

            if (st.Hour > end.Hour)
            {
                end = end.AddDays(1);
            }

            shift.TotalShiftDurationInMins = end.Subtract(st).Duration().TotalMinutes;

            if (!performSave)
            {
                return(shift.ShiftId);
            }

            if (shift.ShiftId > 0)
            {
                shift.SetUpdateDetails(user);
                repository.SaveExisting(shift);
            }
            else
            {
                shift.SetCreateDetails(user);
                repository.SaveNew(shift);
            }

            return(shift.ShiftId);
        }
Esempio n. 6
0
        //
        // GET: /FMM/Shift/Detail
        public async Task <ActionResult> Detail(string key)
        {
            using (ShiftServiceClient client = new ShiftServiceClient())
            {
                MethodReturnResult <Shift> result = await client.GetAsync(key);

                if (result.Code == 0)
                {
                    ShiftViewModel viewModel = new ShiftViewModel()
                    {
                        Name        = result.Data.Key,
                        StartTime   = result.Data.StartTime,
                        EndTime     = result.Data.EndTime,
                        IsOverDay   = result.Data.IsOverDay,
                        CreateTime  = result.Data.CreateTime,
                        Creator     = result.Data.Creator,
                        Description = result.Data.Description,
                        Editor      = result.Data.Editor,
                        EditTime    = result.Data.EditTime
                    };
                    return(PartialView("_InfoPartial", viewModel));
                }
                else
                {
                    ModelState.AddModelError("", result.Message);
                }
            }
            return(PartialView("_InfoPartial"));
        }
        public HttpResponseMessage editShiftForStaff([FromBody] ShiftViewModel shiftDetails)
        {
            IEnumerable <StaffTimesheetsViewModel>    result             = null;
            IEnumerable <OverlappingShiftIdViewModel> overlapCheckResult = null;

            int userID            = -1;
            var authenticatedUser = this.ActionContext.RequestContext.Principal as ClaimsPrincipal;
            var username          = authenticatedUser.Claims.FirstOrDefault(x => x.Type == "user_name").Value;
            var id = _accountService.GetAccountByUsername(username).GordonID;

            userID = Convert.ToInt32(id);

            try
            {
                overlapCheckResult = _jobsService.editShiftOverlapCheck(userID, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME, shiftDetails.ID);
                if (overlapCheckResult.Count() > 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.Conflict, "Error: shift overlap detected"));
                }
                result = _jobsService.editShiftStaff(shiftDetails.ID, shiftDetails.SHIFT_START_DATETIME, shiftDetails.SHIFT_END_DATETIME, shiftDetails.HOURS_WORKED, username);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Esempio n. 8
0
        public async Task <IActionResult> Book(ShiftViewModel viewModel)
        {
            Claim id = HttpContext.User.Claims.Where(x => x.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier").FirstOrDefault();

            if (id == null)
            {
                throw new ArgumentException("http://schemas.microsoft.com/identity/claims/objectidentifier claim is required ");
            }

            IEnumerable <Shift> bookedShifts = this.shiftRepository.Get(x => x.EmployeeId == id.Value);

            if (bookedShifts?.Where(x => x.Start.DayOfYear == viewModel.Start.DayOfYear && x.Start.Year == viewModel.Start.Year).FirstOrDefault() != null)
            {
                ViewData["ValidationError"] = "You are already booked to work on this day.";
                return(await this.Index());
            }

            Shift storeShift = this.shiftRepository.Get(x => x.StoreName == viewModel.StoreName && x.Start == viewModel.Start && x.End == viewModel.End && x.WorkType == viewModel.WorkType && x.Allocated == false).FirstOrDefault();

            if (storeShift == null)
            {
                ViewData["ValidationError"] = "No available shifts at this time.";
                return(await this.Index());
            }

            storeShift.EmployeeId = id.Value;
            storeShift.Allocated  = true;

            await this.shiftRepository.Update(storeShift);

            return(this.ViewShifts());
        }
        public async Task Book_EmployeeNotOnShift_BooksOnShift()
        {
            // Arrange
            IRepository <Library.Models.Shift> shiftRepository = Substitute.For <IRepository <Library.Models.Shift> >();
            DateTime now = DateTime.Now;

            shiftRepository.Get(
                "SELECT * FROM c WHERE c.LocationId = @locationId AND c.StartDateTime = @start AND c.EndDateTime = @end AND c.WorkType = @workType AND c.Allocated = false",
                Arg.Any <IDictionary <string, object> >(), Arg.Any <string>()).Returns(new[]
            {
                new Library.Models.Shift {
                    StartDateTime = now.AddDays(1), LocationId = "1", Allocated = true, EmployeeId = "xyz"
                }
            });
            ILocationService locationService = Substitute.For <ILocationService>();

            locationService.GetByName("Contoso").Returns(new Library.Models.Location {
                id = "1", Name = "Contoso"
            });

            ShiftsController controller = this.GetController(shiftRepository: shiftRepository, locationService: locationService);

            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("http://schemas.microsoft.com/identity/claims/objectidentifier", "123") }));
            ShiftViewModel viewModel = new ShiftViewModel {
                LocationName = "Contoso", Start = now, End = now.AddHours(9), WorkType = "Till"
            };

            // Act
            await controller.Book(viewModel);

            // Assert
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            shiftRepository.Received(1).Update(Arg.Is <Library.Models.Shift>(x => x.EmployeeId == "123" && x.Allocated == true));
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
        public async Task Book_EmployeeNotOnShiftButShiftNotAvailable_ViewDataWarning()
        {
            // Arrange
            IStringLocalizer <ShiftsController> stringLocalizer = Substitute.For <IStringLocalizer <ShiftsController> >();

            stringLocalizer.GetString("NoShiftsAvailable").Returns(new LocalizedString("NoShiftsAvailable", "There are no shifts available."));

            IRepository <Library.Models.Shift> shiftRepository = Substitute.For <IRepository <Library.Models.Shift> >();
            DateTime         now             = DateTime.Now;
            ILocationService locationService = Substitute.For <ILocationService>();

            locationService.Get().Returns(new[] { new Library.Models.Location {
                                                      id = "1", Name = "Contoso"
                                                  } });
            locationService.GetByName("Contoso").Returns(new Library.Models.Location {
                id = "1", Name = "Contoso"
            });

            ShiftsController controller = this.GetController(shiftRepository: shiftRepository, locationService: locationService, stringLocalizer: stringLocalizer);

            controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim("http://schemas.microsoft.com/identity/claims/objectidentifier", "123") }));
            ShiftViewModel viewModel = new ShiftViewModel {
                LocationName = "Contoso", Start = now, End = now.AddHours(9), WorkType = "Till"
            };

            // Act
            IActionResult result = await controller.Book(viewModel);

            // Assert
            ViewResult viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(stringLocalizer["NoShiftsAvailable"], viewResult.ViewData["ValidationError"]);
        }
        public async Task Delete_ShiftViewModel_QueryPassedToRepo()
        {
            // Arrange
            IRepository <Library.Models.Shift> shiftRepository = Substitute.For <IRepository <Library.Models.Shift> >();
            ILocationService locationService = Substitute.For <ILocationService>();

            locationService.Get().Returns(new[] { new Library.Models.Location {
                                                      id = "1", Name = "Contoso"
                                                  }, new Library.Models.Location {
                                                      id = "2", Name = "Fabrikam"
                                                  } });
            ShiftsController controller = this.GetController(shiftRepository: shiftRepository, locationService: locationService);

            DateTime       now       = DateTime.Now;
            ShiftViewModel viewModel = new ShiftViewModel {
                LocationName = "Contoso", Start = now, End = now.AddHours(9), WorkType = "Till"
            };

            // Act
            await controller.Delete(viewModel);

            // Assert
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            shiftRepository.Received(1).Delete(Arg.Any <Expression <Func <Library.Models.Shift, bool> > >());
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
        public async Task ViewShift_NoShifts_ViewDataWarning()
        {
            // Arrange
            DateTime         now             = DateTime.Now;
            ILocationService locationService = Substitute.For <ILocationService>();

            locationService.GetByName("Contoso").Returns(new Library.Models.Location {
                id = "1", Name = "Contoso"
            });

            IStringLocalizer <ShiftsController> stringLocalizer = Substitute.For <IStringLocalizer <ShiftsController> >();

            stringLocalizer.GetString("NoEmployees").Returns(new LocalizedString("NoEmployees", "No employees are booked for this shift."));


            ShiftsController controller = this.GetController(locationService: locationService, stringLocalizer: stringLocalizer);
            ShiftViewModel   viewModel  = new ShiftViewModel {
                LocationName = "Contoso", Start = now, End = now.AddHours(9), WorkType = "Till"
            };

            // Act
            IActionResult result = await controller.ViewShift(viewModel);

            // Assert
            ViewResult viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(stringLocalizer["NoEmployees"], viewResult.ViewData["NoEmployees"]);
        }
Esempio n. 13
0
        public async Task <IActionResult> ViewShift(ShiftViewModel viewModel)
        {
            Location location = await this.GetLocation(viewModel.LocationName);

            IEnumerable <Shift> shifts = await this.shiftRepository.Get(
                "SELECT * FROM c WHERE c.LocationId = @locationId AND c.StartDateTime = @start AND c.EndDateTime = @end AND c.WorkType = @workType",
                new Dictionary <string, object>
            {
                { "@locationId", location.id },
                { "@start", viewModel.Start },
                { "@end", viewModel.End },
                { "@workType", viewModel.WorkType }
            },
                location.id);

            IEnumerable <Shift> bookedShifts = shifts.Where(x => x.EmployeeId != null);

            if (bookedShifts.Count() == 0)
            {
                this.logger.LogInformation("Trying to view shift when there are no employees");
                ViewData["NoEmployees"] = this.stringLocalizer["NoEmployees"];
            }

            List <string> employees = new List <string>();

            foreach (var shift in bookedShifts)
            {
                Microsoft.Graph.User user = await graphServiceClient.Users[shift.EmployeeId].Request().GetAsync();
                employees.Add($"{user.GivenName} {user.Surname}");
            }

            ViewData["Employees"] = employees;

            return(View(viewModel));
        }
Esempio n. 14
0
        private void btnNewShift_Click(object sender, EventArgs e)
        {
            string         newShiftUsername = comStaff.SelectedItem.ToString();
            DateTime       newShiftDate     = dtpShiftDate.Value.Date.AddHours(1);
            ShiftViewModel newShift         = new ShiftViewModel();

            newShift.username  = newShiftUsername;
            newShift.shiftDate = newShiftDate;
            HttpClient client = new HttpClient
            {
                BaseAddress = new Uri("http://localhost:9000/")
            };
            var response = client.PostAsJsonAsync("Create/Shift", newShift).Result;

            if (response.IsSuccessStatusCode)
            {
                MessageBox.Show("New Shift Created.", "New Shift Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dtpShiftDate.Value.ToLocalTime();
            }
            else
            {
                MessageBox.Show("New Shift Creation failed. Please check your credentials and try again. Error Code: " + response.StatusCode.ToString(),
                                "New Shift Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 15
0
        public IActionResult GenerateSchedule(string month, string VoorkeurLeden)
        {
            List <MemberDTO> members = memberRetRepository.GetAll();

            ShiftViewModel shiftViewModel = new ShiftViewModel();

            List <ShiftDTO> membershifts = shiftRetRepository.GetAllShiftsForClub(month);

            foreach (ShiftDTO shift in membershifts)
            {
                scheduleSaveRepository.Shifts.Add(shift);

                scheduleSaveRepository.PlanShifts(members, VoorkeurLeden);
            }

            foreach (ShiftDTO shiftmember in scheduleSaveRepository.Shifts)
            {
                ShiftDetailViewModel model = new ShiftDetailViewModel();

                model.EndMoment   = shiftmember.EndMoment;
                model.StartMoment = shiftmember.StartMoment;
                model.Members     = shiftmember.Members;
                model.ID          = shiftmember.ID;

                shiftViewModel.Shifts.Add(model);
            }

            return(View(shiftViewModel));
        }
Esempio n. 16
0
        public async Task <ActionResult <ShiftViewModel> > RemoveShiftAsync(Guid shiftId)
        {
            if (shiftId == Guid.Empty)
            {
                return(BadRequest("No valid id."));
            }
            try
            {
                TaskResult <Shift> shift = await shiftService.GetShiftAsync(shiftId);

                if (shift == null)
                {
                    return(NotFound("Shift not found"));
                }

                TaskResult <Shift> result = await shiftService.RemoveShiftAsync(shift.Data);

                return(!result.Succeeded
                    ? UnprocessableEntity(new ErrorViewModel
                {
                    Type = Type.Error, Message = result.Message
                })
                    : Ok(ShiftViewModel.CreateVm(result.Data)));
            }
            catch (Exception ex)
            {
                string message = GetType()
                                 .Name + "Error in " + nameof(RemoveShiftAsync);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }
Esempio n. 17
0
        public async Task <ActionResult> SaveModify(ShiftViewModel model)
        {
            using (ShiftServiceClient client = new ShiftServiceClient())
            {
                MethodReturnResult <Shift> result = await client.GetAsync(model.Name);

                if (result.Code == 0)
                {
                    result.Data.StartTime   = model.StartTime;
                    result.Data.EndTime     = model.EndTime;
                    result.Data.IsOverDay   = model.IsOverDay;
                    result.Data.Description = model.Description;
                    result.Data.Editor      = User.Identity.Name;
                    result.Data.EditTime    = DateTime.Now;
                    MethodReturnResult rst = await client.ModifyAsync(result.Data);

                    if (rst.Code == 0)
                    {
                        rst.Message = string.Format(FMMResources.StringResource.Shift_SaveModify_Success
                                                    , model.Name);
                    }
                    return(Json(rst));
                }
                return(Json(result));
            }
        }
Esempio n. 18
0
        public ActionResult ShiftTimeListEdit(ShiftViewModel shift)
        {
            //var companies = db.UserCompanies.Where(w => w.User.UserName == User.Identity.Name).Select(s => s.CompanyId).Distinct().ToList();
            //shift.ShiftList = new SelectList(db.Shifts.Where(w => companies.Contains((int)w.CompanyId)), "ShiftId", "Name");

            return(PartialView("_ShiftTimeList", shift));
        }
Esempio n. 19
0
        public IActionResult UpdateShift(int id, string description, DateTime date, TimeSpan starttime, TimeSpan endtime, int nrofbar, int nrofevent, int nrofextra)
        {
            ShiftModel model = new ShiftModel
            {
                Id          = id,
                Date        = date,
                Description = description,
                EndTime     = endtime,
                StartTime   = starttime,
                NrOfBar     = nrofbar,
                NrOfEvent   = nrofevent,
                NrOfExtra   = nrofextra
            };

            logic.UpdateShift(model);

            ShiftModel viewmodeltransfer = logic.GetShift(id);

            var vm = new ShiftViewModel
            {
                Id          = viewmodeltransfer.Id,
                Date        = viewmodeltransfer.Date,
                Description = viewmodeltransfer.Description,
                EndTime     = viewmodeltransfer.EndTime,
                StartTime   = viewmodeltransfer.StartTime,
                NrOfBar     = viewmodeltransfer.NrOfBar,
                NrOfEvent   = viewmodeltransfer.NrOfEvent,
                NrOfExtra   = viewmodeltransfer.NrOfExtra
            };

            return(RedirectToAction("ChangeShift", vm));
        }
Esempio n. 20
0
        public IActionResult ShiftIndividual(int id)
        {
            ShiftModel     model = logic.GetShift(id);
            ShiftViewModel vm    = new ShiftViewModel(model.Id, model.Description, model.Date, model.StartTime, model.EndTime, model.NrOfBar, model.NrOfEvent, model.NrOfExtra);

            return(View("ShiftIndividual", vm));
        }
Esempio n. 21
0
        public async Task <IActionResult> CancelShift(ShiftViewModel viewModel)
        {
            Claim id = HttpContext.User.Claims.Where(x => x.Type == "http://schemas.microsoft.com/identity/claims/objectidentifier").FirstOrDefault();

            if (id == null)
            {
                ArgumentException exception = new ArgumentException("http://schemas.microsoft.com/identity/claims/objectidentifier claim is required");
                this.logger.LogError(exception, "No id claim present for user");
                throw exception;
            }

            Location location = await this.GetLocation(viewModel.LocationName);

            Shift shift = (await this.shiftRepository.Get(
                               "SELECT * FROM c WHERE c.LocationId = @locationId AND c.StartDateTime = @start AND c.EndDateTime = @end AND c.WorkType = @workType AND c.Allocated = true AND c.EmployeeId = @employeeId",
                               new Dictionary <string, object>
            {
                { "@locationId", location.id },
                { "@start", viewModel.Start },
                { "@end", viewModel.End },
                { "@workType", viewModel.WorkType },
                { "@employeeId", id.Value }
            },
                               location.id)).FirstOrDefault();

            shift.EmployeeId = null;
            shift.Allocated  = false;

            await this.shiftRepository.Update(shift);

            return(RedirectToAction("ViewShifts"));
        }
Esempio n. 22
0
        public async Task <ActionResult <ShiftViewModel> > GetShiftAsync(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(BadRequest());
            }
            try
            {
                TaskResult <Shift> result = await shiftService.GetShiftAsync(id);

                if (!result.Succeeded)
                {
                    return(UnprocessableEntity(new ErrorViewModel {
                        Type = Type.Error, Message = result.Message
                    }));
                }
                if (result.Data == null)
                {
                    return(NotFound());
                }
                return(Ok(ShiftViewModel.CreateVm(result.Data)));
            }
            catch (Exception ex)
            {
                string message = GetType()
                                 .Name + "Error in " + nameof(GetShiftAsync);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }
Esempio n. 23
0
 public ActionResult Post([FromBody] ShiftViewModel model)
 {
     if (model == default(ShiftViewModel))
     {
         return(400.ErrorStatusCode(Constants.BadRequest.ToDict()));
     }
     return(CreateShift(model));
 }
Esempio n. 24
0
        public async Task <IActionResult> Delete(ShiftViewModel viewModel)
        {
            Location location = await this.GetLocation(viewModel.LocationName);

            await this.shiftRepository.Delete(x => x.LocationId == location.id && x.StartDateTime == viewModel.Start && x.EndDateTime == viewModel.End && x.WorkType == viewModel.WorkType);

            return(Redirect("/Shifts"));
        }
Esempio n. 25
0
        public ActionResult ShiftTimeList()
        {
            ShiftViewModel shift = new ShiftViewModel()
            {
                TimeList = (List <ShiftTime>)Utils.Instance.CreateShiftTime(-1, 7)
            };

            return(PartialView("_ShiftTimeList", shift));
        }
Esempio n. 26
0
        public IActionResult Create()
        {
            ShiftViewModel model = new ShiftViewModel
            {
                Drivers  = _combosHelper.GetComboDrivers(),
                Services = _combosHelper.GetComboServices()
            };

            return(View(model));
        }
Esempio n. 27
0
 public async Task <ShiftEntity> ToShiftEntityAsync(ShiftViewModel model, bool isNew)
 {
     return(new ShiftEntity
     {
         Id = isNew ? 0 : model.Id,
         User = await _context.Users.FindAsync(model.User),
         Service = await _context.Services.FindAsync(model.Service),
         Date = model.Date.ToUniversalTime()
     });
 }
Esempio n. 28
0
        public ActionResult SaveShift(ShiftViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(false));
            }
            var response = _lookupService.MapViewModelToShift(model, CurrentUserName, true);

            return(Json(response > 0));
        }
Esempio n. 29
0
        public ActionResult EditShift(ShiftViewModel shift)
        {
            bool   success = false;
            string message = "";

            if (ModelState.IsValid)
            {
                var shiftedit = db.Shifts
                                .Where(w => w.ShiftId == shift.ShiftId).FirstOrDefault();

                if (shiftedit != null)
                {
                    shiftedit.Name        = shift.ShiftName;
                    shiftedit.Description = shift.ShiftDescription;
                    shiftedit.UpdatedAt   = DateTime.Now;
                    shiftedit.IsActive    = shift.IsActive;
                    shiftedit.ExtraHourId = shift.ExtraHourId;

                    db.Entry(shiftedit).State = EntityState.Modified;
                }

                foreach (var t in shift.TimeList)
                {
                    ShiftTime shifttime = db.ShiftTimes.Find(t.ShiftTimeId);

                    if (shifttime != null)
                    {
                        shifttime.StartTime       = t.StartTime;
                        shifttime.EndTime         = t.EndTime;
                        shifttime.HasLunchTime    = t.HasLunchTime;
                        shifttime.IsLaborDay      = t.IsLaborDay;
                        shifttime.IsActive        = t.IsActive;
                        shifttime.LunchEndTime    = t.LunchEndTime;
                        shifttime.LunchStartTime  = t.LunchStartTime;
                        shifttime.UpdatedAt       = DateTime.Now;
                        db.Entry(shifttime).State = EntityState.Modified;
                    }
                }

                try {
                    db.SaveChanges();

                    MyLogger.GetInstance.Info("Shift was edited successfull, Id: " + shift.ShiftId);

                    success = true;
                }
                catch (Exception e)
                {
                    message = e.Message;
                    success = false;
                    MyLogger.GetInstance.Error("Error", e);
                }
            }
            return(Json(new { success = success, message = message }));
        }
Esempio n. 30
0
 public async Task <JsonResult> Archived(ShiftViewModel model, bool archive)
 {
     try {
         var data = _shiftService.GetByID(model.ID).Result;
         data.UpdatedAt  = TimeUtility.GetTimeZoneByName(CurrentUser.TimeZone);
         data.UpdatedBy  = CurrentUser.ID;
         data.IsArchived = archive;
         _shiftService.Update(data);
         return(Json(new { success = true }));
     } catch { return(Json(new { success = false })); }
 }