public IHttpActionResult Add(Warehouse warehouseModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var  retId       = _warehouseService.Add(warehouseModel);
                bool IsDuplicate = retId == 0;

                if (IsDuplicate == true)
                {
                    Log.Info($"{typeof(WarehouseController).FullName}||{UserEnvironment}||Add record not successful, Warehouse Code is duplicate.");
                    return(Content(HttpStatusCode.Forbidden, "Warehouse Code is Duplicate"));
                }

                Log.Info($"{typeof(WarehouseController).FullName}||{UserEnvironment}||Add record successful.");

                var response = Request.CreateResponse(HttpStatusCode.Created);
                var test     = JsonConvert.SerializeObject(new
                {
                    id      = retId,
                    message = "Warehouse added"
                });
                response.Content = new StringContent(test, Encoding.UTF8, "appliation/json");
                return(ResponseMessage(response));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Beispiel #2
0
        public async Task <int> Add(FishPondModel _model)
        {
            if (_model.DefaultWarehouseId.GetValueOrDefault(0) == 0)
            {
                scopeContext.AddError("Chưa chọn kho");
                return(0);
            }
            if (_model.FarmRegionId == 0)
            {
                scopeContext.AddError("Chưa chọn vùng nuôi");
                return(0);
            }
            using (var transaction = context.Database.BeginTransaction())
            {
                // create new fish-pond-type warehouse
                Warehouse warehouse = new Warehouse()
                {
                    DefaultWarehouseId = _model.DefaultWarehouseId.Value,
                    FarmRegionId       = _model.FarmRegionId,
                    Name            = FISHPONDTYPE_WAREHOUSE_PREFIX + _model.Name,
                    WarehouseTypeId = DEFAULT_FISHPONDTYPE_WAREHOUSE_TYPE
                };
                var warehouseId = await svcWarehouse.Add(warehouse);

                FishPond entity = iMapper.Map <FishPond>(_model);
                entity.WarehouseId = warehouseId;
                entity.Id          = await svcFishPond.Add(entity);

                transaction.Commit();
                return(entity.Id);
            }
        }
Beispiel #3
0
        public IActionResult Add(Warehouse warehouse)
        {
            var result = _warehouseService.Add(warehouse);

            if (result.Success)
            {
                return(Ok(JsonConvert.SerializeObject(result.Message)));
            }
            return(BadRequest(JsonConvert.SerializeObject(result.Message)));
        }
Beispiel #4
0
 public IActionResult Create([Bind("WarehouseID,Ref,Name,LocationId")] Warehouse warehouse)
 {
     if (ModelState.IsValid)
     {
         service.Add(warehouse);
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["LocationId"] = new List <SelectListItem>(service.GetListLocationsIsWarehouse());
     return(View(warehouse));
 }
Beispiel #5
0
 public JavaScriptResult Create(WareHouseViewModel warehousevm)
 {
     try
     {
         _warehouseService.Add(Mapper.Map <Warehouse>(warehousevm));
         return(JavaScript($"ShowResult('{"Data saved successfully."}','{"success"}','{"redirect"}','{"/Warehouse"}')"));
     }
     catch (Exception ex)
     {
         return(JavaScript($"ShowResult('{ex.Message}','failure')"));
     }
 }
Beispiel #6
0
        public async Task <IActionResult> Add(Warehouse model)
        {
            if (model == null)
            {
                return(BadRequest());
            }
            if (ModelState.IsValid)
            {
                var result = await _service.Add(model);

                return(Ok(result));
            }
            return(BadRequest());
        }
Beispiel #7
0
        public ActionResult Create(WarehouseViewModel warehouseViewModel)
        {
            Warehouse warehouse = warehouseViewModel.Warehouse;

            foreach (string course in warehouseViewModel.SelectedCourses)
            {
                warehouse.GetType().GetProperty(course).SetValue(warehouse, true, null);
            }
            try
            {
                warehouseService.Add(warehouse);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(warehouseViewModel));
            }
        }
Beispiel #8
0
        public void Post([FromBody] WarehouseRequestModel entity)
        {
            if (entity == null)
            {
                throw new HttpRequestException(_errorHandler.GetErrorMessage(ErrorMessagesEnum.EntityNull));
            }

            if (!ModelState.IsValid)
            {
                throw new HttpRequestException(string.Format(_errorHandler.GetErrorMessage(ErrorMessagesEnum.ModelValidation), ModelState.Values.First().Errors.First().ErrorMessage));
            }
            if (_service.GetById(entity.Id) != null)
            {
                throw new HttpRequestException(_errorHandler.GetErrorMessage(ErrorMessagesEnum.EntityDuplicate));
            }
            var request = _mapper.Map <WarehouseRequestModel, WarehouseResponse>(entity);

            _service.Add(request);
        }
        public HttpResponseMessage Create(HttpRequestMessage request, WarehouseViewModel warehouseViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newWarehouse = new Warehouse();
                    newWarehouse.UpdateWarehouse(warehouseViewModel);
                    newWarehouse.CreatedDate = DateTime.Now;
                    _warehouseService.Add(newWarehouse);
                    _warehouseService.Save();

                    var responseData = Mapper.Map <Warehouse, WarehouseViewModel>(newWarehouse);
                    response = request.CreateResponse(HttpStatusCode.Created, responseData);
                }

                return response;
            }));
        }
Beispiel #10
0
        public async Task <int> Add(WarehouseModel _model)
        {
            Warehouse entity = iMapper.Map <Warehouse>(_model);

            return(await svcWarehouse.Add(entity));
        }
 public async Task <IActionResult> Add(PostWarehouseDto warehouseDto) => Ok(await _service.Add(warehouseDto));
Beispiel #12
0
 public async Task <ActionResult <Response> > Post([FromBody] WarehouseAddOrUpdateModel model)
 {
     return(Ok(await _warehouseService.Add(model)));
 }