Esempio n. 1
0
        public IActionResult Create()
        {
            var model = new ScheduleInputModel();

            model.DistrictItems = this.districtService.GetAllAsKeyValuePairs();
            return(this.View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create(ScheduleInputModel model)
        {
            try
            {
                model.DistrictItems = this.districtService.GetAllAsKeyValuePairs();

                if (!this.ModelState.IsValid)
                {
                    return(this.View(model));
                }

                if (model.RaiseDate.Month != DateTime.Now.Month || model.RaiseDate.Year != DateTime.Now.Year)
                {
                    this.ModelState.AddModelError(string.Empty, "RaiseDate is not in current monthh and/or year!");
                    return(this.View(model));
                }

                if (model.RaiseTimeFrom.Hours < 8 || model.RaiseTimeFrom.Hours > 12)
                {
                    this.ModelState.AddModelError(string.Empty, "Raise Time From should be between  8:00 and 13:00!");
                    return(this.View(model));
                }

                if (model.RaiseTimeTo.Hours < 13 || model.RaiseTimeTo.Hours > 18)
                {
                    this.ModelState.AddModelError(string.Empty, "Raise Time From should be between  13:00 and 18:00!");
                    return(this.View(model));
                }

                if (model.DistrictId == 0)
                {
                    this.ModelState.AddModelError(string.Empty, "Please fill districts!");
                    return(this.View(model));
                }

                var user = await this.userManager.GetUserAsync(this.User);

                await this.scheduleService.CreateAsync(model, user.Id);

                this.TempData["Message"] = "The schedule was added successfully.";

                return(this.RedirectToAction("All"));
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View());
            }
        }
Esempio n. 3
0
        public async Task CreateAsync(ScheduleInputModel input, string userId)
        {
            var schedule = new Schedule
            {
                Description   = input.Description,
                RaiseDate     = input.RaiseDate,
                RaiseTimeFrom = input.RaiseTimeFrom,
                RaiseTimeTo   = input.RaiseTimeTo,
                ObjectTypeId  = (int)input.ObjectType,
                DistrictId    = input.DistrictId,
            };

            await this.schedulesRepository.AddAsync(schedule);

            await this.schedulesRepository.SaveChangesAsync();
        }
 public UpdateScheduleCommand(long id, ScheduleInputModel input, Guid userId)
 {
     Id     = id;
     Model  = input;
     UserId = userId;
 }
Esempio n. 5
0
 public async Task Patch(long id, [FromBody] ScheduleInputModel input)
 {
     var command = new UpdateScheduleCommand(id, input, UserId);
     await _mediator.Send(command);
 }
Esempio n. 6
0
        public async Task <BooleanResult> Post([FromBody] ScheduleInputModel input)
        {
            var command = new CreateScheduleCommand(input, UCenterUser);

            return(await _mediator.Send(command));
        }
 public CreateScheduleCommand(ScheduleInputModel model, UserDto user)
 {
     Model = model;
     User  = user;
 }