Esempio n. 1
0
 public IHttpActionResult Update(int id, users user)
 {
     if (id != user.user_id)
     {
         return(BadRequest());
     }
     try
     {
         user.password             = SecurePasswordHasher.Hash(user.password);
         context.Entry(user).State = EntityState.Modified;
         context.SaveChanges();
         return(Ok(user));
     }
     catch (Exception)
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     }
 }
        public IHttpActionResult Create(employees employee)
        {
            dynamic Response = new ExpandoObject();

            try
            {
                if (!ModelState.IsValid)
                {
                    Response.Status  = Helpers.ResponseStatus.ERROR;
                    Response.Message = Helpers.ErrorMessage.BAD_REQUEST;
                    return(Content(HttpStatusCode.BadRequest, Response));
                }

                var employeeDTO = Mapper.Map <employees, EmployeeDTO>(employee);

                employee.password = SecurePasswordHasher.Hash(employee.password);
                context.employees.Add(employee);
                context.SaveChanges();

                Response.Status    = Helpers.ResponseStatus.OK;
                Response.Employees = employeeDTO;

                return(Ok(Response));
            }
            catch (Exception)
            {
                Response.Status  = Helpers.ResponseStatus.ERROR;
                Response.Message = Helpers.ErrorMessage.INTERNAL_SERVER_ERROR;
                return(Content(HttpStatusCode.InternalServerError, Response));
            }

            /*try
             * {
             *  employee.password = SecurePasswordHasher.Hash(employee.password);
             *  context.employees.Add(employee);
             *  context.SaveChanges();
             * }
             * catch (Exception)
             * {
             *  throw new HttpResponseException(HttpStatusCode.BadRequest);
             * }
             * return Ok(employee);*/
        }