예제 #1
0
        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));
        }
예제 #2
0
        public async Task <IActionResult> AddPosition(
            [FromRoute] Guid organizationId, [FromRoute] int positionId)
        {
            var result = await _positionService.Add(_agencyOwner, positionId);

            return(Ok(result));
        }
예제 #3
0
 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());
 }
예제 #4
0
 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));
        }
예제 #6
0
        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"));
            }
        }
예제 #8
0
        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;
            }));
        }
예제 #9
0
        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);
        }
예제 #10
0
 public Task <IResultModel> Add(PositionAddModel model)
 {
     return(_service.Add(model));
 }
 public override Response Handle(AddPositionRequest request)
 {
     _positionService.Add(request.Name);
     return(CreateDefaultResponse());
 }
예제 #12
0
        public async Task <IActionResult> Add([FromBody] PositionsArrayDTO positionsDTO)
        {
            await _positionService.Add(_mapper.Map <List <Position> >(positionsDTO.Position));

            return(new OkObjectResult(true));
        }
예제 #13
0
 public IActionResult Post([FromBody] Position model)
 {
     return(Ok(
                _s.Add(model)));
 }
예제 #14
0
        public IActionResult Create(CreatePostionDto createPostionDto)
        {
            var position = _positionService.Add(createPostionDto);

            return(CreatedAtAction(nameof(Get), new { id = position.Id }, position));
        }