public async Task <IActionResult> PutEmployeeShifts(Guid id, EmployeeShifts employeeShifts)
        {
            if (id != employeeShifts.UID)
            {
                return(BadRequest());
            }

            _context.Entry(employeeShifts).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!EmployeeShiftsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    _logger.LogError("Exception while updateing employee shift", ex);
                    return(StatusCode((int)Status.Failure, new { message = "Failed to update employee shift" }));
                }
            }

            return(StatusCode((int)Status.Success, new { message = "Employee shift updated successfully" }));
        }
        public ActionResult EmployeeShiftDelete(int id)
        {
            EmployeeShifts empShift = _serviceEmployeeShifts.GetById(id);

            empShift.IsActive = false;
            _serviceEmployeeShifts.Update(empShift);
            return(RedirectToAction("EmployeeShiftList"));
        }
        public ActionResult EmployeeShiftInsert(EmployeeShiftsModel empShiftModel)
        {
            EmployeeShifts emps = empShiftModel.ModelToEnity();

            emps.IsActive = true;
            _serviceEmployeeShifts.Insert(emps);
            return(RedirectToAction("EmployeeShiftList"));
        }
 private bool IsValidSwap(EmployeeShifts shift1, EmployeeShifts shift2)
 {
     if ((shift1.StartTime > shift2.StartTime && shift1.StartTime < shift2.EndTime) ||
         (shift1.EndTime > shift2.StartTime && shift1.EndTime < shift2.EndTime))
     {
         return(false);
     }
     return(true);
 }
Пример #5
0
        public ActionResult AdminShiftAllocation()
        {
            ViewBag.RequestLevelPerson = "Admin";
            EmployeeShifts shiftEmployees = new EmployeeShifts();

            using (var client = new ShiftClient())
            {
                shiftEmployees.Shifts         = client.GetShiftMaster().OrderBy(p => p.FromTime).ToList();
                shiftEmployees.shiftEmployees = client.GetShiftDetailsForUsers(this.UserId, "Admin");
            }
            return(View("ShiftAllocation", shiftEmployees));
        }
        public async Task <ActionResult <EmployeeShifts> > PostEmployeeShifts(EmployeeShifts employeeShifts)
        {
            try
            {
                _context.EmployeeShifts.Add(employeeShifts);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetEmployeeShifts", new { id = employeeShifts.UID }, employeeShifts));
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception while creating employee shift", ex);
                return(StatusCode((int)Status.Failure, new { message = "Exception while creating employee shift. Exception: " + ex.StackTrace }));
            }
        }
        public static EmployeeShifts ModelToEnity(this EmployeeShiftsModel model, bool virtualActive = false)
        {
            EmployeeShifts entity = new EmployeeShifts()
            {
                DailyWages = model.DailyWages,
                EmployeeId = model.EmployeeId,
                ShiftId    = model.ShiftId,

                Id       = model.Id,
                IsActive = model.IsActive
            };

            if (virtualActive)
            {
                entity.Employee = model.Employee.ModelToEntity();
                entity.Shift    = model.Shift.ModelToEnity();
            }
            return(entity);
        }
        public static EmployeeShifts ModelToEnity(this EmployeeShiftsModel model, bool virtualActive = false)
        {
            EmployeeShifts entity = new EmployeeShifts()
            {
                DailyWages = model.DailyWages,
                EmployeeId = model.EmployeeId,
                ShiftId = model.ShiftId,

                Id = model.Id,
                IsActive = model.IsActive
            };
            if (virtualActive)
            {
                entity.Employee = model.Employee.ModelToEntity();
                entity.Shift = model.Shift.ModelToEnity();

            }
            return entity;
        }
        private static List <EmployeeShifts> ConvertToDataModel(List <EmployeeDep> EmployeeData)
        {
            var employeeShiftList = new List <EmployeeShifts>();

            //run on all records from DB
            foreach (var empItem in EmployeeData)
            {
                //find if emplyee's shift exsist in my list
                var currEmp = employeeShiftList.FirstOrDefault(x => x.EmployeeId == empItem.ID);

                if (currEmp != null)
                {    //if not - add it to the list
                    currEmp.Shifts.Add(new Shift
                    {
                        ID        = empItem.Shiftid.Value,
                        Date      = empItem.ShiftDate.Value,
                        EndTime   = empItem.EndShift.Value,
                        StartTime = empItem.StartShift.Value
                    });
                }
                else
                {
                    var empShifts = new EmployeeShifts(empItem.ID, empItem.FirstName,
                                                       empItem.LastName, empItem.DepName, empItem.StartWorkYear);

                    if (empItem.Shiftid.HasValue)
                    {
                        empShifts.Shifts.Add(new Shift
                        {
                            ID        = empItem.Shiftid.Value,
                            Date      = empItem.ShiftDate.Value,
                            EndTime   = empItem.EndShift.Value,
                            StartTime = empItem.StartShift.Value
                        });
                    }
                    employeeShiftList.Add(empShifts);
                }
            }

            return(employeeShiftList);
        }
        public async Task <ActionResult <EmployeeShifts> > GetEmployeeShifts(Guid id)
        {
            EmployeeShifts employeeShifts = null;

            try
            {
                employeeShifts = await _context.EmployeeShifts.FindAsync(id);
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception while getting employee shift", ex);
            }


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

            return(employeeShifts);
        }
 public static EmployeeShiftsModel EntityToModel(this EmployeeShifts entity, bool virtualActive = false)
 {
     try
     {
         EmployeeShiftsModel model = new EmployeeShiftsModel()
         {
             DailyWages = entity.DailyWages,
             EmployeeId = entity.EmployeeId,
             ShiftId    = entity.ShiftId,
             IsActive   = entity.IsActive,
             Id         = entity.Id
         };
         if (virtualActive)
         {
             model.Shift    = entity.Shift.EntityToModel();
             model.Employee = entity.Employee.EntityToModel();
         }
         return(model);
     }
     catch (Exception)
     {
         return(new EmployeeShiftsModel());
     }
 }