Exemplo n.º 1
0
        public HttpResponseMessage Add([FromBody] EmployeeModel employeeModel)
        {
            //Validate the object recived against the database model constraints
            if (ModelState.IsValid)
            {
                try
                {
                    //Map EmployeeModel To Person Object
                    Person person = MapEmployeeModelToPerson(employeeModel);

                    //call the businessLogic Implimentation repo to create Person
                    Person createdPerson = _iPersonLogicRepository.CreatePerson(person);

                    //Map EmployeeModel To Employee Object
                    Employee employee = MapEmployeeModelToEmployee(employeeModel);

                    //add created person to the employee object
                    employee.PersonId = createdPerson.PersonId;

                    //call the businessLogic Implimentation repo to create Employee
                    Employee createdEmployee = _iEmployeeLogicRepository.CreateEmployee(employee);

                    //Save the model and return the model with Id
                    return(Request.CreateResponse(HttpStatusCode.Created, createdEmployee));
                }
                catch (Exception e)
                {
                    Log.Info("________________________________________________________________" +
                             "\nClass: EmployeeController \n Method: Add \n Expetion: " + e.InnerException?.Message);
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Something Went Wrong When Creating A New Employee!!"));
                }
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
        }
        public HttpResponseMessage Add([FromBody] Person person)
        {
            //Validate the object recived against the database model constraints
            if (ModelState.IsValid)
            {
                try
                {
                    //call the businessLogic Implimentation repo to create Person
                    Person createdPerson = _iPersonLogicRepository.CreatePerson(person);

                    //Save the model and return the model with Id
                    return(Request.CreateResponse(HttpStatusCode.Created, createdPerson));
                }
                catch (Exception e)
                {
                    Log.Info("________________________________________________________________" +
                             "\nClass: PersonController \n Method: Add \n Expetion: " + e.InnerException?.Message);
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Something Went Wrong When Creating A New Person!!"));
                }
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
        }