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()); }
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); }
public List <BrandModel> GetAllBrands() { BrandData oBrandDataService = new BrandData(); IEnumerable <BrandModel> brands = oBrandDataService.GetAll(); return(brands.ToList()); }
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); }
/// <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; }
/// <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 }); }
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); }
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); }
public IHttpActionResult PostBrand(BrandData brand) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var node = brandBLL.Create(brand.ToModel()); return(Ok(node.ToViewData())); }
internal bool DoesBrandExist(int id) { bool exist = true; BrandData brandData = new BrandData(); var data = brandData.GetBrandById(id); if (data == null) { exist = false; } return(exist); }
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()) }); }
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))); }
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); }
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); }
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); }
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")); } }
public bool DeleteBrand(int brandId) { BrandData oBrandDataService = new BrandData(); return(oBrandDataService.Delete(brandId)); }
public ItemController() { data = new ItemData(); bData = new BrandData(); pData = new ProductTypeData(); }