public async Task <IActionResult> Save(TRequest <PositionRequest> request) { if (request == null) { return(NotFound()); } var response = new Response <int>(); try { if (request.value.Id == 0) { response.Data = await _positionService.Add(request.value); response.Message = "Thêm thành công"; response.Success = true; } else { response.Data = await _positionService.Update(request.value); response.Message = "Sửa thành công"; response.Success = true; } } catch (Exception ex) { response.Success = false; response.Message = ex.Message + "," + ex.InnerException; } return(Ok(response)); }
public async Task <IActionResult> AddPosition( [FromRoute] Guid organizationId, [FromRoute] int positionId) { var result = await _positionService.Add(_agencyOwner, positionId); return(Ok(result)); }
public ActionResult Create([Bind(Include = "Name")] PositionVM positionVM) { if (ModelState.IsValid) { PositionDTO positionDTO = Mapper.Map <PositionDTO>(positionVM); _positionService.Add(positionDTO); return(RedirectToAction("Index")); } return(View()); }
public async Task <ActionResult <PositionDTO> > Add(PositionDTO position) { try { return(await service.Add(position)); } catch (CustomException ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> AddPosition(PositionViewModel positionModel) { if (ModelState.IsValid) { _positionService.Add(positionModel.Name); return(RedirectToAction("Index", "Admin")); } return(View(positionModel)); }
public ActionResult PositionSave([DataSourceRequest] DataSourceRequest dsRequest, Position position) { var positionDetails = _positionService.GetPositionDetails().Where(model => model.PositionName == position.PositionName && model.PositionName != position.PositionName); if (positionDetails.Count() > 0) { ModelState.AddModelError(string.Empty, "Postion already exists, please create with other name."); } else if (ModelState.IsValid) { if (position.PositionId == 0) { _positionService.Add(position); return(Json(position)); } } return(Json(ModelState.ToDataSourceResult())); }
public ActionResult Add(Position pos) { if (string.IsNullOrEmpty(pos.Name)) { return(Content("error! position name is required!")); } int count = PositionService.LoadEntities(t => t.Name.Equals(pos.Name)).Count(); if (count > 0) { //已有此记录,不处理 return(Content("ok")); } else { PositionService.Add(pos); return(Content("ok")); } }
public HttpResponseMessage Post(HttpRequestMessage request, PositionViewModel PositionVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { Position newPosition = new Position(); newPosition.UpdatePosition(PositionVm); var responseData = _positionService.Add(newPosition); _positionService.Save(); response = request.CreateResponse(HttpStatusCode.Created, responseData); } return response; })); }
public async Task <IActionResult> CreatePositionAsync([FromBody] PositionDto position) { _logger.LogInformation("CreatePositionAsync() method start."); var model = position.Map(); // Add Position object to the database var addResponse = await Task.FromResult(_positionService.Add(model)); if (addResponse.HasErrors) { if (addResponse.Exception != null) { var exceptionMessage = $"Error in CreatePositionAsync() method. Position object may not have been added to database. Exception was thrown in PositionService. Exception Type: '{addResponse.Exception.GetType()}'. Exception Message: {addResponse.Exception.Message}"; _logger.LogError(exceptionMessage); return(BadRequest(addResponse.ErrorMessage)); } var message = $"Error in CreatePositionAsync() method. Position object may not have been added to database. Error message returned from PositionService: {addResponse.ErrorMessage}"; _logger.LogError(message); return(NotFound(addResponse.ErrorMessage)); } var addedObject = addResponse.Result; var dto = addedObject.Map(); var id = addedObject.Id; _logger.LogInformation($"CreatePositionAsync() method end with Position id '{id}'."); var actionResult = CreatedAtAction( actionName: nameof(GetPositionByIdAsync), // ASP.NET Core 3.0 bug: https://stackoverflow.com/questions/59288259/asp-net-core-3-0-createdataction-returns-no-route-matches-the-supplied-values //controllerName: ControllerContext.ActionDescriptor.ControllerName, routeValues: new { id }, value: dto); return(actionResult); }
public Task <IResultModel> Add(PositionAddModel model) { return(_service.Add(model)); }
public override Response Handle(AddPositionRequest request) { _positionService.Add(request.Name); return(CreateDefaultResponse()); }
public async Task <IActionResult> Add([FromBody] PositionsArrayDTO positionsDTO) { await _positionService.Add(_mapper.Map <List <Position> >(positionsDTO.Position)); return(new OkObjectResult(true)); }
public IActionResult Post([FromBody] Position model) { return(Ok( _s.Add(model))); }
public IActionResult Create(CreatePostionDto createPostionDto) { var position = _positionService.Add(createPostionDto); return(CreatedAtAction(nameof(Get), new { id = position.Id }, position)); }