Esempio n. 1
0
        public async Task <IActionResult> AddTableAppointment([Bind("TableId, AppointmentId")] TableAppointmentViewModel viewModel)
        {
            var tableAppointmentResult = await _tableService.AddTableAppointmentAsync(viewModel.TableId, viewModel.AppointmentId);

            if (tableAppointmentResult.Succeeded)
            {
                return(RedirectToAction(nameof(Details), new { id = viewModel.TableId }));
            }
            else
            {
                var appointmentResult = await _appointmentService.GetEntitiesAsync();

                if (appointmentResult.Succeeded)
                {
                    List <SelectListItem> selectList = appointmentResult.Value.Select(a => new SelectListItem
                    {
                        Value = a.Id.ToString(),
                        Text  = string.Join(" - ", a.Start, a.End)
                    }).ToList();

                    viewModel.Appointments.AddRange(selectList);
                }

                ModelState.AddModelStateErrors(tableAppointmentResult.Errors);
                return(View(viewModel));
            }
        }
        public async Task <IActionResult> Create([Bind("Start,End,Id")] AppointmentModel model)
        {
            var appointmentDto = _mapper.Map <AppointmentDto>(model);
            var result         = await _service.InsertAsync(appointmentDto);

            if (!result.Succeeded)
            {
                ModelState.AddModelStateErrors(result.Errors);
                return(View());
            }

            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Name,Id")] TableModel tableModel)
        {
            var table  = _mapper.Map <TableDto>(tableModel);
            var result = await _tableService.InsertAsync(table);

            if (!result.Succeeded)
            {
                ModelState.AddModelStateErrors(result.Errors);

                return(View());
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Start,End,Id")] AppointmentModel model)
        {
            var appointmentDto = _mapper.Map <AppointmentDto>(model);
            var result         = await _service.UpdateAsync(appointmentDto);

            if (result.Errors.ContainsKey(Errors.NotFound))
            {
                return(NotFound());
            }

            if (result.Succeeded)
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelStateErrors(result.Errors);
                return(View(model));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Name,Id")] TableModel model)
        {
            TableDto table  = _mapper.Map <TableDto>(model);
            var      result = await _tableService.UpdateAsync(table);

            if (result.Errors.ContainsKey(Errors.NotFound))
            {
                return(NotFound());
            }

            if (result.Succeeded)
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                ModelState.AddModelStateErrors(result.Errors);
                return(View(model));
            }
        }