public IActionResult PutActionType(ActionTypeUM model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var actionTypeInDb = _actionTypeService.GetByID(model.ID); if (actionTypeInDb == null) { return(NotFound("ID not found!")); } var nameExist = _actionTypeService.GetByName(model.Name); if (nameExist != null) { return(BadRequest("ActionType Name is existed!")); } _mapper.Map(model, actionTypeInDb); _actionTypeService.Save(); return(Ok("success")); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <ActionType> PostActionType(ActionTypeCM model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { ActionType actionType = new ActionType(); actionType = _mapper.Map <ActionType>(model); _actionTypeService.Create(actionType); _actionTypeService.Save(); return(StatusCode(201, "Action Type Created!")); } catch (Exception e) { return(BadRequest(e.Message)); } }