public IHttpActionResult Create([FromBody] CreatePositionDto position) { if (position == null) { return(BadRequest()); } if (!ModelState.IsValid) { string errorMessage = new ModelStateError(_logger).OutputMessage(ModelState); return(BadRequest(errorMessage)); } try { _positionService.Create(position); } catch (LogicalException ex) { return(BadRequest(ex.Message)); } catch { return(BadRequest(AppSettings.INTERNAL_SERVER_ERROR_MESSAGE)); } return(Ok()); }
public async Task <ActionResult <Position_PositionDTO> > Create([FromBody] Position_PositionDTO Position_PositionDTO) { if (UnAuthorization) { return(Forbid()); } if (!ModelState.IsValid) { throw new BindException(ModelState); } if (!await HasPermission(Position_PositionDTO.Id)) { return(Forbid()); } Position Position = ConvertDTOToEntity(Position_PositionDTO); Position = await PositionService.Create(Position); Position_PositionDTO = new Position_PositionDTO(Position); if (Position.IsValidated) { return(Position_PositionDTO); } else { return(BadRequest(Position_PositionDTO)); } }
public async Task <IHttpActionResult> Createposition() { ResponseDataDTO <position> response = new ResponseDataDTO <position>(); try { var path = Path.GetTempPath(); if (!Request.Content.IsMimeMultipartContent("form-data")) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType)); } MultipartFormDataStreamProvider streamProvider = new MultipartFormDataStreamProvider(path); await Request.Content.ReadAsMultipartAsync(streamProvider); if (streamProvider.FormData["pos_name"] == null) { response.Code = HttpCode.INTERNAL_SERVER_ERROR; response.Message = "Chức vụ không được để trống"; response.Data = null; return(Ok(response)); } // get data from formdata PositionCreateViewModel positionCreateViewModel = new PositionCreateViewModel { pos_name = Convert.ToString(streamProvider.FormData["pos_name"]), pos_competence = Convert.ToString(streamProvider.FormData["pos_competence"]), pos_abilty = Convert.ToString(streamProvider.FormData["pos_abilty"]), pos_authority = Convert.ToString(streamProvider.FormData["pos_authority"]), pos_responsibility = Convert.ToString(streamProvider.FormData["pos_responsibility"]), pos_description = Convert.ToString(streamProvider.FormData["pos_description"]), }; // mapping view model to entity var createdposition = _mapper.Map <position>(positionCreateViewModel); // save new position _positionservice.Create(createdposition); // return response response.Code = HttpCode.OK; response.Message = MessageResponse.SUCCESS; response.Data = createdposition; return(Ok(response)); } catch (Exception ex) { response.Code = HttpCode.INTERNAL_SERVER_ERROR; response.Message = ex.Message; response.Data = null; Console.WriteLine(ex.ToString()); return(Ok(response)); } }
public ActionResult Create([Bind(Include = "PositionId,PositionTitle")] PositionViewModel position) { if (ModelState.IsValid) { _positionService.Create(position); return(RedirectToAction("Index")); } return(View(position)); }
public void UpdatePosition(long id, PositionModel positionModel) { var car = dataStore.Get <Car>(id); if (car == null) { throw new EntityNotFoundException($"Запись типа {typeof(Car).Name} c идентификатором {id} не существует"); } if (car.PositionId.HasValue) { positionService.Update(car.PositionId.Value, positionModel.Latitude, positionModel.Longitude); } else { car.Position = positionService.Create(positionModel.Latitude, positionModel.Longitude); dataStore.SaveChanges(); } }
public async Task <IActionResult> Post([FromBody] List <Position> positions) { try { return(Ok(await _positionService.Create(positions))); } catch (Exception e) { return(BadRequest(new { message = e.Message })); } }
public IActionResult CreatePosition([FromBody] PositionData positionData) { if (ModelState.IsValid) { Position position = positionData.Position; service.Create(position); return(Ok(position.Id)); } else { return(BadRequest(ModelState)); } }
public async Task <IActionResult> Create([FromBody] PositionCreateRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var result = await _positionService.Create(request); if (!result.IsSuccessed) { return(BadRequest(result)); } return(Ok(result)); }
public void ApplyToEntity(Container container, IDataStore dataStore, IPositionService positionService) { container.Number = this.Number; container.Description = this.Description; container.Status = this.Status; container.Position = this.Position?.ToEntity(); container.Address = this.Address; container.ContainerType = dataStore.FindById <ContainerTypes.Entities.ContainerType>(this.ContainerTypeId); if (container.PositionId.HasValue) { positionService.Update(container.PositionId.Value, PositionLatitude, PositionLongitude); } else { container.Position = positionService.Create(PositionLatitude, PositionLongitude); } }
public void ApplyToEntity(Polygon polygon, IPositionService positionService) { polygon.Number = this.Number; polygon.Description = this.Description; polygon.Name = this.Name; polygon.Status = this.Status; polygon.Phone = this.Phone?.Replace("%2B", "+"); polygon.Address = this.Address; if (polygon.PositionId.HasValue) { positionService.Update(polygon.PositionId.Value, PositionLatitude, PositionLongitude); } else { polygon.Position = positionService.Create(PositionLatitude, PositionLongitude); } }
public void ApplyToEntity(Car car, IDataStore dataStore, IPositionService positionService) { car.Number = this.Number; car.Mark = this.Mark; car.Serviceability = Enum .GetValues(typeof(CarServiceability)) .Cast <CarServiceability>() .FirstOrDefault(x => x.ToString() == this.Serviceability); if (car.PositionId.HasValue) { positionService.Update(car.PositionId.Value, PositionLatitude, PositionLongitude); } else { car.Position = positionService.Create(PositionLatitude, PositionLongitude); } }
public void ApplyToEntity(Customer customer, IDataStore dataStore, IPositionService positionService) { customer.Number = this.Number; customer.Description = this.Description; customer.Status = this.Status; customer.Position = this.Position?.ToEntity(); customer.Name = this.Name; customer.Phone = this.Phone; customer.ContactPersonName = this.ContactPersonName; customer.ContactPersonPhone = this.ContactPersonPhone; customer.Inn = this.Inn; customer.Address = this.Address; customer.IsBlocked = this.IsBlocked; if (customer.PositionId.HasValue) { positionService.Update(customer.PositionId.Value, PositionLatitude, PositionLongitude); } else { customer.Position = positionService.Create(PositionLatitude, PositionLongitude); } }
public void ApplyToEntity(Request request, IDataStore dataStore, IPositionService positionService, ICustomerService customerService) { if (request.Id == 0) { request.CreateDateTime = DateTime.Now; } request.PlannedDateTime = DateTime.Parse(this.PlannedDate); if (!string.IsNullOrEmpty(ExecutionDate)) { request.ExecutionDateTime = DateTime.Parse(this.ExecutionDate); } request.Container = dataStore.FindById <Container>(this.ContainerId); request.Type = this.Type; //"малые" контейнеры - забор через 3 дня, "большие" - через день var daysCountForUninstall = request.Container?.ContainerType.Capacity <= 8 ? 3 : 1; request.PlannedUninstallDateTime = string.IsNullOrEmpty(PlannedUninstallDate) ? (request.Type == RequestType.Install ? request.PlannedDateTime.AddDays(daysCountForUninstall) : (DateTime?)null) : DateTime.Parse(this.PlannedUninstallDate); request.Address = this.Address; request.ContactPersonName = this.ContactPersonName; request.ContactPersonPhone = this.ContactPersonPhone; request.Comment = this.Comment; request.Status = this.Status; request.PaymentType = this.PaymentType; request.IsPaid = this.IsPaid ? Enums.IsPaid.Yes : Enums.IsPaid.No; request.Sum = this.Sum; request.Polygon = dataStore.FindById <Polygon>(this.PolygonId); request.Customer = dataStore.FindById <Customer>(this.CustomerId); request.Car = dataStore.FindById <Car>(this.CarId); request.Driver = dataStore.FindById <Driver>(this.DriverId); if (request.PositionId.HasValue) { positionService.Update(request.PositionId.Value, PositionLatitude, PositionLongitude); } else { request.Position = positionService.Create(PositionLatitude, PositionLongitude); } //создаем нового if (this.CustomerId == "0") { var customerDbEntity = customerService.GetAllCustomerModels(null) .FirstOrDefault(x => x.Phone == CustomerPhone); if (customerDbEntity == null) { var createModel = new CustomerSaveModel { Address = this.Address, ContactPersonPhone = this.ContactPersonPhone, ContactPersonName = this.ContactPersonName, Name = this.CustomerName, Phone = this.CustomerPhone, PositionLatitude = request.Position?.Latitude, PositionLongitude = request.Position?.Longitude }; var customer = customerService.Create(createModel); request.CustomerId = customer.Id; } else { request.CustomerId = customerDbEntity.Id; } } request.Address = Address; request.ContactPersonName = ContactPersonName; request.ContactPersonPhone = ContactPersonPhone; }
// POST: api/Position public void Post([FromBody] PositionDto value) { service.Create(value); }
public BaseResponse <PositionOutputDto> Create([FromBody] PositionInputDto position) { return(_positionService.Create(position)); }