Ejemplo n.º 1
0
        public async Task <ActionResult <Student> > PostStudent(StudentModel model)
        {
            Object meta;

            try
            {
                if (!Enumeration.ExistName <HouseType>(model.Casa))
                {
                    meta = new
                    {
                        Error = new { Description = "Error en los datos del estudiante", Data = "La casa seleccionada no es valida" }
                    };
                    return(BadRequest(new { Meta = meta }));
                }

                Student student = Mapper.Map <Student>(model);

                await Repository.CreateAsync <Student>(student);

                return(CreatedAtAction("GetStudent", new { id = student.ID }, student));
            }
            catch (Exception exception)
            {
                Logger.Fatal(exception.Message);
                Logger.Fatal(exception.StackTrace);
                meta = new { Error = new { Description = "Error Interno Del Servidor." } };
                return(StatusCode(500, new { Meta = meta }));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateStudent(Guid id, StudentModel model)
        {
            Object meta;

            try
            {
                if (id != model.ID)
                {
                    return(BadRequest());
                }
                if (!Enumeration.ExistName <HouseType>(model.Casa))
                {
                    meta = new
                    {
                        Error = new { Description = "Error en los datos del estudiante", Data = "La casa seleccionada no es valida" }
                    };
                    return(BadRequest(new { Meta = meta }));
                }

                var student = await Repository.SelectById <Student>(id);

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

                student.Nombre         = model.Nombre;
                student.Apellido       = model.Apellido;
                student.Identificacion = model.Identificacion;
                student.Edad           = model.Edad;
                student.Casa           = HouseType.FromName <HouseType>(model.Casa).Value;

                await Repository.UpdateAsync <Student>(student);

                return(NoContent());
            }
            catch (Exception exception)
            {
                Logger.Fatal(exception.Message);
                Logger.Fatal(exception.StackTrace);
                meta = new { Error = new { Description = "Error Interno Del Servidor." } };
                return(StatusCode(500, new { Meta = meta }));
            }
        }