public IActionResult Update([FromRoute] int id, [FromBody] ScheduleCreateOrEtitRequest request)
        {
            var actionResult = new CustomActionResult
            {
                Successful = true,
                Message    = "Schedule was successfull updated!"
            };

            var scheduleId = request.ScheduleId ?? 0;
            var schedule   = new Schedule();

            if (request.ScheduleId.HasValue)
            {
                schedule = _scheduleService.GetById(scheduleId);
            }
            else
            {
                actionResult.Successful = false;
                actionResult.Message    = "Selected Schedule can not be found!";
            }

            foreach (var vendingMachineId in request.VendingMachineIds)
            {
                var vendingMachineSchedule = new VendingMachineSchedule
                {
                    VendingMachineId = vendingMachineId
                };
                vendingMachineSchedule.SetAudit(CurrentLoggedUserId);
                schedule.VendingMachineSchedules.Add(vendingMachineSchedule);
            }

            try
            {
                var dbSchedule = _scheduleService.Update(schedule);
                actionResult.EntityId = dbSchedule.Id;
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Update schedule was unsuccessfully, please try again!";

                return(Ok(actionResult));
            }

            return(Ok(actionResult));
        }
        public IActionResult Create([FromBody] ScheduleCreateOrEtitRequest request)
        {
            var schedule = new Schedule();

            schedule.Day           = request.Day;
            schedule.FieldWorkerId = request.FieldWorkerId;
            schedule.SetAudit(CurrentLoggedUserId);

            var vendingMachineSchedules = new List <VendingMachineSchedule>();

            foreach (var id in request.VendingMachineIds)
            {
                var vendingMachineSchedule = new VendingMachineSchedule
                {
                    VendingMachineId = id
                };
                vendingMachineSchedule.SetAudit(CurrentLoggedUserId);
                vendingMachineSchedules.Add(vendingMachineSchedule);
            }

            schedule.VendingMachineSchedules = vendingMachineSchedules;

            var actionResult = new CustomActionResult
            {
                Successful = true,
                Message    = "Schedule was successfull created!"
            };

            try
            {
                var dbSchedule = _scheduleService.Create(schedule);
                actionResult.EntityId = dbSchedule.Id;
            }
            catch
            {
                actionResult.Successful = false;
                actionResult.Message    = "Create schedule was unsuccessfully, please try again!";

                return(Ok(actionResult));
            }

            return(Ok(actionResult));
        }