Esempio n. 1
0
        public async void Edit()
        {
            ErrorMessages = null;

            var horarioConsulta = new WpfHorarioConsultaModel {
                Id        = SelectedHorarioConsulta.Id, Weekday = SelectedDiaSemana, StartHour = StartHourInForm,
                EndHour   = EndHourInForm, Place = PlaceInForm, EliminationDate = EliminationDateInForm,
                MateriaId = SelectedMateria?.Id, ProfesorId = SelectedUsuarioProfesor?.Id
            };

            try {
                var entity = _mapper.Map <HorarioConsulta>(horarioConsulta);

                await _horarioConsultaEndpoint.Put(entity, _usuarioLogged.Token);
                await LoadHorariosConsulta();
            } catch (UnauthorizedRequestException) {
                ErrorMessages = new BindingList <string> {
                    "No tiene acceso"
                };
            } catch (BadRequestException ex) {
                ErrorMessages = new BindingList <string>(ex.Errors.Select(kvp => string.Join(". ", kvp.Value)).ToList());
            } catch (Exception ex) {
                ErrorMessages = new BindingList <string> {
                    $"{ex.Message} Ha ocurrido un error. Por favor contacte a soporte"
                };
            }
        }
Esempio n. 2
0
        // Logic Delete - POST HorarioConsulta/ID
        public async Task <ActionResult> LogicDelete(int?id)
        {
            if (id == null)
            {
                return(Content("Debe incluir el id"));
            }

            try {
                await _horarioConsultaEndpoint.Get(id, _userSession.BearerToken);

                var horarioConsultaTask = _horarioConsultaEndpoint.Get(id, _userSession.BearerToken);
                await Task.WhenAll(horarioConsultaTask);

                var horarioConsulta = _mapper.Map <MvcHorarioConsultaModel>(source: horarioConsultaTask.Result);

                if (horarioConsulta.EliminationDate == null)
                {
                    horarioConsulta.EliminationDate = DateTime.Today.Date;
                }
                else
                {
                    return(Content("Este elemento ya estaba eliminado lógicamente"));
                }

                var entity = _mapper.Map <HorarioConsulta>(source: horarioConsulta);
                await _horarioConsultaEndpoint.Put(entity, _userSession.BearerToken);
            } catch (UnauthorizedRequestException) {
                return(RedirectToAction("AccessDenied", "Error"));
            } catch (NotFoundRequestException ex) {
                return(Content($"{ex.StatusCode}: Elemento no encontrado"));
            } catch (Exception ex) {
                return(RedirectToAction("SpecificError", "Error", new { error = ex.Message }));
            }

            // TempData may be used to check in the view whether the deletion was successful or not
            TempData["SuccessMessage"] = "Logic Deleted Sucessfully";
            // return Content("OK");
            return(Content("OK"));
        }