コード例 #1
0
ファイル: BrandsController.cs プロジェクト: ztxyzu/wx_public
        public IHttpActionResult PutBrand(int id, BrandData brand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != brand.Id)
            {
                return(BadRequest());
            }

            //db.Entry(brand).State = EntityState.Modified;
            try
            {
                brandBLL.Update(brand.ToModel());
            }
            catch (Exception ex)
            {
                if (!BrandExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw ex;
                }
            }
            return(Ok());
        }
コード例 #2
0
        public HttpResponseMessage Put(int id, [FromBody][System.Web.Mvc.Bind(Include = "Brand")] BrandModel Brand)
        {
            HttpResponseMessage response;
            ModelsValidation    validation = new ModelsValidation();
            BrandData           data       = new BrandData();

            if (ModelState.IsValid)
            {
                if (validation.DoesBrandExist(id) == false)
                {
                    response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "There is no brand with given Id parameter." });
                }
                else
                {
                    data.UpdateBrandById(id, Brand.Brand);
                    response = Request.CreateResponse(HttpStatusCode.NoContent);
                }
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Model is invalid.", ModelValidation = "Brand name must be between 2 - 64 signs. Cannot be null or empty." });
            }

            return(response);
        }
コード例 #3
0
        public List <BrandModel> GetAllBrands()
        {
            BrandData oBrandDataService     = new BrandData();
            IEnumerable <BrandModel> brands = oBrandDataService.GetAll();

            return(brands.ToList());
        }
コード例 #4
0
        public HttpResponseMessage Delete(int id)
        {
            HttpResponseMessage response;
            ModelsValidation    validation = new ModelsValidation();
            BrandData           data       = new BrandData();

            if (validation.DoesBrandExist(id) == false)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "There is no brand with given Id parameter." });
            }
            else
            {
                try
                {
                    data.DeleteBrandById(id);
                    response = Request.CreateResponse(HttpStatusCode.NoContent);
                }
                catch (SqlException sqlException)
                {
                    response = CheckSqlExceptionNumber(sqlException.Number);
                }
            }

            return(response);
        }
コード例 #5
0
 /// <summary>
 /// Helper method to copy data from a <see cref="BrandData"/>
 /// to a <see cref="BrandInfo"/> instance.
 /// </summary>
 /// <param name="info">The full data instance.</param>
 /// <param name="data">The data instance.</param>
 public static void CopyFrom(this BrandInfo info, BrandData data)
 {
     info.Description = data?.Description;
     info.Link        = data?.Link;
     info.Order       = data?.Order;
     info.RoleName    = data?.Role;
 }
コード例 #6
0
 /// <summary>
 /// Helper method to convert a <see cref="BrandInfo"/> instance
 /// to a <see cref="BrandData"/> instance.
 /// </summary>
 /// <param name="data">The data instance.</param>
 /// <returns>The converted data.</returns>
 public static BrandInfo ToBrandInfo(this BrandData data)
 {
     return(new BrandInfo()
     {
         Name = data?.Name,
         Description = data?.Description,
         Link = data?.Link,
         Order = data?.Order,
         RoleName = data?.Role
     });
 }
コード例 #7
0
        public bool Update(int id, BrandData brandData)
        {
            bool isUpdated = brandRepository.Update(id, new Demo_API_BeerAPI.DAL.Entities.BrandEntity()
            {
                Name         = brandData.Name,
                Country      = brandData.Country,
                CreationYear = brandData.CreationYear
            });

            return(isUpdated);
        }
コード例 #8
0
        public int Add(BrandData brandData)
        {
            int newId = brandRepository.Insert(new Demo_API_BeerAPI.DAL.Entities.BrandEntity()
            {
                Name         = brandData.Name,
                Country      = brandData.Country,
                CreationYear = brandData.CreationYear
            });

            return(newId);
        }
コード例 #9
0
ファイル: BrandsController.cs プロジェクト: ztxyzu/wx_public
        public IHttpActionResult PostBrand(BrandData brand)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var node = brandBLL.Create(brand.ToModel());

            return(Ok(node.ToViewData()));
        }
コード例 #10
0
        internal bool DoesBrandExist(int id)
        {
            bool exist = true;

            BrandData brandData = new BrandData();
            var       data      = brandData.GetBrandById(id);

            if (data == null)
            {
                exist = false;
            }

            return(exist);
        }
コード例 #11
0
 public static Brand ToModel(this BrandData node)
 {
     return(new Brand()
     {
         Id = node.Id,
         Name = node.Name,
         MeterType = node.MeterType,
         Producer = node.Producer,
         Model = node.Model,
         Description = node.Description,
         IsControllable = node.IsControllable,
         IsFJNewcapSystem = node.IsFJNewcapSystem
                            //Parameters = node.Parameters.Select(x => x.ToViewData())
     });
 }
コード例 #12
0
        public IHttpActionResult AddNewBrand([FromBody] BrandData data)
        {
            if (data is null || !ModelState.IsValid)
            {
                return(BadRequest("Data is required !"));
            }

            if (BrandService.Instance.Exists(data.Name))
            {
                return(BadRequest($"The brand {data.Name} already exists"));
            }

            int newId = BrandService.Instance.Add(data);

            return(Json(BrandService.Instance.GetOne(newId)));
        }
コード例 #13
0
        public HttpResponseMessage Post([FromBody] BrandModel Brand)
        {
            HttpResponseMessage response;
            BrandData           data = new BrandData();

            if (ModelState.IsValid)
            {
                data.SaveBrand(Brand.Brand);
                response = Request.CreateResponse(HttpStatusCode.Created);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Model is invalid.", ModelValidation = "Brand name must be between 2 - 64 signs. Cannot be null or empty." });
            }

            return(response);
        }
コード例 #14
0
        public HttpResponseMessage Get()
        {
            BrandData           data   = new BrandData();
            List <BrandDBModel> brands = data.GetBrands();

            HttpResponseMessage response;

            if (brands.Count() <= 0)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "No data found." });
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.OK, brands);
            }

            return(response);
        }
コード例 #15
0
        public HttpResponseMessage Get(int id)
        {
            if (id <= 0)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Id parameter must be greater than 0." }));
            }

            BrandData    data  = new BrandData();
            BrandDBModel brand = data.GetBrandById(id);

            HttpResponseMessage response;

            if (brand == null)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "No data found matching given id." });
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.OK, brand);
            }

            return(response);
        }
コード例 #16
0
        public IHttpActionResult UpdateBrand(int id, [FromBody] BrandData data)
        {
            if (data is null || !ModelState.IsValid)
            {
                return(BadRequest("Data is required !"));
            }

            if (BrandService.Instance.GetOne(id) is null)
            {
                return(BadRequest($"The brand '{id}' does not exists"));
            }

            bool isUpdated = BrandService.Instance.Update(id, data);

            if (isUpdated)
            {
                return(Json(BrandService.Instance.GetOne(id)));
            }
            else
            {
                return(BadRequest("An error occurred during the request"));
            }
        }
コード例 #17
0
        public bool DeleteBrand(int brandId)
        {
            BrandData oBrandDataService = new BrandData();

            return(oBrandDataService.Delete(brandId));
        }
コード例 #18
0
 public ItemController()
 {
     data  = new ItemData();
     bData = new BrandData();
     pData = new ProductTypeData();
 }