Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Year,Week,Day,GroupId,EmployeeId,StartTime,EndTime")] DutyRoster dutyRoster)
        {
            if (id != dutyRoster.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dutyRoster);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DutyRosterExists(dutyRoster.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(dutyRoster));
        }
Esempio n. 2
0
        public async Task <SaveDutyRosterResponse> UpdateAsync(int id, DutyRoster dutyRoster)
        {
            var existingDutyRoster = await _dutyRosterRepository.FindByIdAsync(id);

            if (existingDutyRoster == null)
            {
                return(new SaveDutyRosterResponse("Duty Roster not found."));
            }

            //existingDutyRoster.Shift_Id=dutyRoster.Shift_Id;
            existingDutyRoster.From_Date        = dutyRoster.From_Date;
            existingDutyRoster.To_Date          = dutyRoster.To_Date;
            existingDutyRoster.Shift.Name       = dutyRoster.Shift.Name;
            existingDutyRoster.Shift.Start_Time = dutyRoster.Shift.Start_Time;
            existingDutyRoster.Shift.End_Time   = dutyRoster.Shift.End_Time;

            try
            {
                _dutyRosterRepository.Update(existingDutyRoster);
                await _unitOfWork.CompleteAsync();

                return(new SaveDutyRosterResponse(existingDutyRoster));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveDutyRosterResponse($"An error occurred when saving the Department: {ex.Message}"));
            }
        }
Esempio n. 3
0
        public void ItCreatesAGuard()
        {
            var d = new DutyRoster();
            var s = Event.GuardStartsShift("[1518-11-01 00:05]", 10);

            d.OnEvent((ShiftStartEvent)s);

            Assert.Equal(new Guard(10), d.GuardOnDuty);
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id,Year,Week,Day,GroupId,EmployeeId,StartTime,EndTime")] DutyRoster dutyRoster)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dutyRoster);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dutyRoster));
        }
Esempio n. 5
0
        public async Task <IActionResult> AddDutyRoster(DutyRoster roster)
        {
            //DutyRoster dutyRoster = (DutyRoster)roster;

            //[Bind("Id,Year,Week,Day,GroupId,EmployeeId,StartTime,EndTime")] DutyRoster dutyRoster
            //if (ModelState.IsValid)
            //{
            //}
            _context.Add(roster);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));

            // return View(roster);
        }
Esempio n. 6
0
        public IHttpActionResult Post([FromBody] CreateDutyRosterModel model)
        {
            var duty = new DutyRoster
            {
                Date      = model.Date,
                StartTime = model.StartTime,
                EndTime   = model.EndTime,
                Display   = true
            };

            db.DutyRoster.Add(duty);
            db.SaveChanges();

            return(Ok(duty.Id));
        }
Esempio n. 7
0
        public async Task <SaveDutyRosterResponse> SaveAsync(DutyRoster dutyRoster)
        {
            try
            {
                await _dutyRosterRepository.AddAsync(dutyRoster);

                await _unitOfWork.CompleteAsync();

                return(new SaveDutyRosterResponse(dutyRoster));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveDutyRosterResponse($"An error occurred when saving the Department: {ex.Message}"));
            }
        }
      public async Task <IActionResult> PostAsync([FromBody] DutyRoster dutyRoster)
      {           //get data form _departmentService by id
          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState.GetErrorMessages()));
          }
          //otherwise data save in database
          var result = await _dutyRosterService.SaveAsync(dutyRoster);

          //if result is not success show error Message
          if (!result.Success)
          {
              return(BadRequest(result.Message));
          }

          return(Ok());
      }
      public async Task <IActionResult> PutAsync(int id, [FromBody] DutyRoster resource)
      {           // if Model is invalid show error message by using ModelState
          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState.GetErrorMessages()));
          }
          //get data form EmployeeAttendenceResource by id using AutoMapper
          //var dutyRoster=_mapper.Map<SaveDutyRosterResource,DutyRoster>(resource);
          //update data by id
          var result = await _dutyRosterService.UpdateAsync(id, resource);

          //if update data is null

          if (result == null)
          {
              return(BadRequest(result));
          }
          //get result data from SaveDepartmentResource after update data using automapper
          var roleResource = _mapper.Map <DutyRoster, DutyRosterResource>(result.DutyRoster);

          //show data
          return(Ok(roleResource));
      }
Esempio n. 10
0
        // GET: DutyRosters
        public async Task <IActionResult> Index(short searchYear, short searchWeek, short weekChange)
        {
            var employees = from e in _context.Employees
                            select e;

            var groups = from g in _context.Groups
                         select g;

            CultureInfo myCI  = new CultureInfo("de-DE");
            Calendar    myCal = myCI.Calendar;

            // Gets the DTFI properties required by GetWeekOfYear.
            CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;

            System.DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;

            var dutyRoster = new DutyRoster();

            if (searchYear > 0 && searchWeek > 0)
            {
                if (weekChange == -1)
                {
                    if (searchWeek == 1)
                    {
                        dutyRoster.Year = (short)(searchYear - 1);
                        dutyRoster.Week = 52;
                    }
                    else
                    {
                        dutyRoster.Year = searchYear;
                        dutyRoster.Week = (short)(searchWeek - 1);
                    }
                }
                else if (weekChange == 1)
                {
                    if (searchWeek == 52)
                    {
                        dutyRoster.Year = (short)(searchYear + 1);
                        dutyRoster.Week = 1;
                    }
                    else
                    {
                        dutyRoster.Year = searchYear;
                        dutyRoster.Week = (short)(searchWeek + 1);
                    }
                }
                else
                {
                    dutyRoster.Year = searchYear;
                    dutyRoster.Week = searchWeek;
                }
            }
            else
            {
                // Displays the number of the current week relative to the beginning of the year.
                //Console.WriteLine("The CalendarWeekRule used for the en-US culture is {0}.", myCWR);
                //Console.WriteLine("The FirstDayOfWeek used for the en-US culture is {0}.", myFirstDOW);
                //Console.WriteLine("Therefore, the current week is Week {0} of the current year.", myCal.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW));
                dutyRoster.Year = (short)DateTime.Today.Year;
                dutyRoster.Week = (short)myCal.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW);
            }

            var rosters = from r in _context.DutyRosters
                          where r.Year == dutyRoster.Year && r.Week == dutyRoster.Week
                          select r;

            var joinedDataRostersEmployees = rosters.AsQueryable().Join
                                                 (employees,
                                                 roster => roster.EmployeeId,
                                                 empoyee => empoyee.Id,
                                                 (roster, employee) =>
                                                 new
            {
                Id           = roster.Id,
                Year         = roster.Year,
                Week         = roster.Week,
                Day          = roster.Day,
                GroupId      = roster.GroupId,
                EmployeeId   = roster.EmployeeId,
                StartTime    = roster.StartTime,
                EndTime      = roster.EndTime,
                EmployeeName = employee.Surname + ", " + employee.Forename
            });

            List <DutyRosterModel> dutyRosterModels = new List <DutyRosterModel>();

            foreach (var item in joinedDataRostersEmployees)
            {
                dutyRosterModels.Add(
                    new DutyRosterModel
                {
                    Id           = item.Id,
                    Year         = item.Year,
                    Week         = item.Week,
                    Day          = item.Day,
                    GroupId      = item.GroupId,
                    EmployeeId   = item.EmployeeId,
                    StartTime    = item.StartTime,
                    EndTime      = item.EndTime,
                    EmployeeName = item.EmployeeName
                }
                    );
            }

            var firstDayInWeek = ISOWeek.ToDateTime(dutyRoster.Year, dutyRoster.Week, myFirstDOW).Date;

            var daysOfWeek = new List <Models.DayOfWeek>();

            Models.DayOfWeek dayOfWeek = new Models.DayOfWeek();

            for (int i = 0; i < 7; i++)
            {
                dayOfWeek = new Models.DayOfWeek
                {
                    Index   = i,
                    DayName = firstDayInWeek.AddDays(i).DayOfWeek.ToString(),
                    Date    = firstDayInWeek.AddDays(i)
                };
                daysOfWeek.Add(dayOfWeek);
            }

            var dutyRosterModel = new DutyRosterIndexModel
            {
                DutyRosters = dutyRosterModels,
                Employees   = await employees.ToListAsync(),
                Groups      = await groups.ToListAsync(),
                DutyRoster  = dutyRoster,
                DaysOfWeek  = daysOfWeek
            };

            return(View(dutyRosterModel));
        }
 public void Update(DutyRoster dutyRoster)
 {
     _context.DutyRoster.Update(dutyRoster);
 }
 public void Remove(DutyRoster dutyRoster)
 {
     _context.DutyRoster.Remove(dutyRoster);
 }
 // add new DutyRoster Item
 public async Task AddAsync(DutyRoster dutyRoster)
 {
     await _context.DutyRoster.AddAsync(dutyRoster);
 }
 private SaveDutyRosterResponse(bool success, string message, DutyRoster dutyRoster) : base(success, message)
 {
     DutyRoster = dutyRoster;
 }
 /// <summary>
 /// Creates a success response.
 /// </summary>
 /// <param name="point">Saved dutyRoster.</param>
 /// <returns>Response.</returns>
 public SaveDutyRosterResponse(DutyRoster dutyRoster) : this(true, string.Empty, dutyRoster)
 {
 }