コード例 #1
0
        public IActionResult postStore([FromBody] StoreAPIModel param)
        {
            bool exist = _context.Store.Any(x => x.Id == param.Id);

            if (!exist)
            {
                try
                {
                    var data = new Store()
                    {
                        Code        = param.Code,
                        Address     = param.Address,
                        Address2    = param.Address2,
                        Address3    = param.Address3,
                        Address4    = param.Address4,
                        City        = param.City,
                        DateOpen    = param.DateOpen,
                        Name        = param.Name,
                        Location    = param.Location,
                        Regional    = param.Regional,
                        StoreTypeId = param.StoreTypeId,
                        TargetQty   = param.TargetQty,
                        WarehouseId = param.WarehouseId,
                        TargetValue = param.TargetValue
                    };

                    _context.Store.Add(data);
                    _context.SaveChanges();

                    response.code    = "1";
                    response.message = "Data has been successfully saved";
                } catch (Exception ex)
                {
                    response.code    = "0";
                    response.message = ex.ToString();
                }
            }
            else
            {
                response.code    = "5";
                response.message = "Data already exists";
            }


            return(Ok(response));
        }
コード例 #2
0
        public IActionResult getStoreById(int Id)
        {
            var param = _context.Store.Where(x => x.Id == Id).FirstOrDefault();
            var model = new StoreAPIModel
            {
                Id          = param.Id,
                Code        = param.Code,
                Address     = param.Address,
                Address2    = param.Address2,
                Address3    = param.Address3,
                Address4    = param.Address4,
                City        = param.City,
                DateOpen    = param.DateOpen,
                Name        = param.Name,
                Location    = param.Location,
                Regional    = param.Regional,
                StoreTypeId = param.StoreTypeId,
                TargetQty   = param.TargetQty,
                WarehouseId = param.WarehouseId,
                TargetValue = param.TargetValue
            };

            return(Ok(model));
        }
コード例 #3
0
        public IActionResult putStore(int id, [FromBody] StoreAPIModel param)
        {
            var dataObject = _context.Store.Where(x => x.Id == param.Id).First();

            if (dataObject.Id != 0)
            {
                try
                {
                    if (param.Address != null)
                    {
                        dataObject.Address = param.Address;
                    }

                    if (param.Address2 != null)
                    {
                        dataObject.Address2 = param.Address2;
                    }

                    if (param.Address3 != null)
                    {
                        dataObject.Address3 = param.Address3;
                    }

                    if (param.Address4 != null)
                    {
                        dataObject.Address4 = param.Address4;
                    }

                    if (param.Address != null)
                    {
                        dataObject.Address = param.Address;
                    }

                    if (param.City != null)
                    {
                        dataObject.City = param.City;
                    }

                    if (param.DateOpen != null)
                    {
                        dataObject.DateOpen = param.DateOpen;
                    }

                    if (param.Name != null)
                    {
                        dataObject.Name = param.Name;
                    }

                    if (param.Location != null)
                    {
                        dataObject.Location = param.Location;
                    }

                    if (param.Regional != null)
                    {
                        dataObject.Regional = param.Regional;
                    }

                    if (param.StoreTypeId != null)
                    {
                        dataObject.StoreTypeId = param.StoreTypeId;
                    }

                    if (param.TargetQty != null)
                    {
                        dataObject.TargetQty = param.TargetQty;
                    }

                    if (param.WarehouseId != null)
                    {
                        dataObject.WarehouseId = param.WarehouseId;
                    }

                    if (param.TargetValue != null)
                    {
                        dataObject.TargetValue = param.TargetValue;
                    }

                    _context.Store.Update(dataObject);
                    _context.SaveChanges();

                    response.code    = "1";
                    response.message = "Data has been successfully updated";
                }
                catch (Exception ex)
                {
                    response.code    = "0";
                    response.message = ex.ToString();
                }
            }
            else
            {
                response.code    = "5";
                response.message = "Data does not exists";
            }


            return(Ok(response));
        }