Exemplo n.º 1
0
        public IActionResult Post([FromBody] StudentInsertModel student)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                var result = unitOfWork.Student.Insert(student);

                return(Ok(new { result }));
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Exceptions occurred in post student api");

                return(StatusCode(500, ex.Message));
            }
        }
Exemplo n.º 2
0
        public bool Insert(StudentInsertModel model)
        {
            try
            {
                var student = new Student()
                {
                    FirstName = model.FirstName,
                    SurName   = model.SurName,
                    Age       = model.Age
                };

                Add(student);

                Log.Information("Created student {0}", model.SurName);

                return(true);
            }
            catch (System.Exception ex)
            {
                Log.Error(ex, "Exceptions occurred in student insert");

                return(false);
            }
        }