public IHttpActionResult PutLaptopBrand(int id, LaptopBrand laptopBrand) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != laptopBrand.ID) { return(BadRequest()); } db.Entry(laptopBrand).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LaptopBrandExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult GetLaptopBrand(int id) { LaptopBrand laptopBrand = db.LaptopBrands.Find(id); if (laptopBrand == null) { return(NotFound()); } return(Ok(laptopBrand)); }
public IHttpActionResult PostLaptopBrand(LaptopBrand laptopBrand) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.LaptopBrands.Add(laptopBrand); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = laptopBrand.ID }, laptopBrand)); }
public IHttpActionResult DeleteLaptopBrand(int id) { LaptopBrand laptopBrand = db.LaptopBrands.Find(id); if (laptopBrand == null) { return(NotFound()); } db.LaptopBrands.Remove(laptopBrand); db.SaveChanges(); return(Ok(laptopBrand)); }
public async Task <IHttpActionResult> ApproveLaptopBrand(int id) { LaptopBrand mobile = await db.LaptopBrands.FindAsync(id); if (mobile == null) { return(NotFound()); } if (mobile.status == "a") { return(BadRequest("Already approved")); } mobile.status = "a"; await db.SaveChangesAsync(); return(Ok("approved")); }
private void button4_Click(object sender, EventArgs e) { if (brandNameText.Text.Length < 2 || brandNameText.Text.Length > 15) { MessageBox.Show("Brand name must between 2-15 characters"); return; } var search = ( from x in de.LaptopBrands where x.LaptopBrandName.Equals(brandNameText.Text) select x.LaptopBrandName ).FirstOrDefault(); if (search == brandNameText.Text) { MessageBox.Show("Username already exist!"); return; } if (insert) { LaptopBrand obj = new LaptopBrand(); obj.LaptopBrandID = brandID; obj.LaptopBrandName = brandNameText.Text; de.LaptopBrands.Add(obj); insert = false; } if (update) { var temp = ( from x in de.LaptopBrands where x.LaptopBrandID.Equals(brandIdText.Text) select x ).FirstOrDefault(); temp.LaptopBrandID = brandIdText.Text; temp.LaptopBrandName = brandNameText.Text; update = false; } de.SaveChanges(); MessageBox.Show("Data has been successfully inserted/updated"); loadData(); }
private IBrandLaptopFactory FactoryProvider(LaptopBrand brand) { IBrandLaptopFactory factory = null; switch (brand) { case LaptopBrand.apple: factory = new AppleLaptopFactory(); break; case LaptopBrand.hp: factory = new HPLaptopFactory(); break; default: break; } return(factory); }
public Laptop OrderLaptop(LaptopBrand brand) { return(CreateLaptop(FactoryProvider(brand))); }
public async Task <bool> addNewBrandModel(string brand, string model, string category) { if (brand != null) { brand.Trim(); } if (model != null) { model.Trim(); } if (brand == "" || brand == "undefined" || brand == null) { return(true); } if (category == "Mobiles") { var isNew = db.Mobiles.Any(x => x.brand.Equals(brand)); if (!isNew) { Mobile mob = new Mobile(); mob.brand = brand; mob.addedBy = User.Identity.GetUserId(); mob.status = "a"; mob.time = DateTime.UtcNow; db.Mobiles.Add(mob); await db.SaveChangesAsync(); if (model != null && model != "" && model != "undefined") { MobileModel mod = new MobileModel(); mod.addedBy = User.Identity.GetUserId(); mod.brandId = mob.Id; mod.status = "a"; mod.time = DateTime.UtcNow; mod.model = model; db.MobileModels.Add(mod); await db.SaveChangesAsync(); } } else { var isNewModel = db.MobileModels.Any(x => x.model.Equals(model)); if (!isNewModel) { if (model != null && model != "" && model != "undefined") { var brandId = db.Mobiles.First(x => x.brand.Equals(brand)); MobileModel mod = new MobileModel(); mod.addedBy = User.Identity.GetUserId(); mod.brandId = brandId.Id; mod.status = "a"; mod.time = DateTime.UtcNow; mod.model = model; db.MobileModels.Add(mod); await db.SaveChangesAsync(); } } } } else if (category == "Laptops") { var isNew = db.LaptopBrands.Any(x => x.brand.Equals(brand)); if (!isNew) { LaptopBrand mob = new LaptopBrand(); mob.brand = brand; mob.addedBy = User.Identity.GetUserId(); mob.status = "a"; mob.time = DateTime.UtcNow; db.LaptopBrands.Add(mob); await db.SaveChangesAsync(); if (model != null && model != "" && model != "undefined") { LaptopModel mod = new LaptopModel(); mod.addedBy = User.Identity.GetUserId(); mod.brandId = mob.Id; mod.status = "a"; mod.time = DateTime.UtcNow; mod.model = model; db.LaptopModels.Add(mod); await db.SaveChangesAsync(); } } else { var isNewModel = db.LaptopModels.Any(x => x.model.Equals(model)); if (!isNewModel) { if (model != null && model != "" && model != "undefined") { LaptopModel mod = new LaptopModel(); mod.addedBy = User.Identity.GetUserId(); mod.brandId = db.LaptopBrands.First(x => x.brand.Equals(brand)).Id; mod.status = "a"; mod.time = DateTime.UtcNow; mod.model = model; db.LaptopModels.Add(mod); await db.SaveChangesAsync(); } } } } else if (category == "Bikes") { var isNew = db.BikeBrands.Any(x => x.brand.Equals(brand)); if (!isNew) { BikeBrand mob = new BikeBrand(); mob.brand = brand; mob.addedBy = User.Identity.GetUserId(); mob.status = "a"; mob.time = DateTime.UtcNow; db.BikeBrands.Add(mob); await db.SaveChangesAsync(); if (model != null && model != "" && model != "undefined") { BikeModel mod = new BikeModel(); mod.addedBy = User.Identity.GetUserId(); mod.brandId = mob.Id; mod.status = "a"; mod.time = DateTime.UtcNow; mod.model = model; db.BikeModels.Add(mod); await db.SaveChangesAsync(); } } else { var isNewModel = db.BikeModels.Any(x => x.model.Equals(model)); if (!isNewModel) { if (model != null && model != "" && model != "undefined") { BikeModel mod = new BikeModel(); mod.addedBy = User.Identity.GetUserId(); mod.brandId = db.BikeBrands.First(x => x.brand.Equals(brand)).Id; mod.status = "a"; mod.time = DateTime.UtcNow; mod.model = model; db.BikeModels.Add(mod); await db.SaveChangesAsync(); } } } } else if (category == "Cars") { var isNew = db.CarBrands.Any(x => x.brand.Equals(brand)); if (!isNew) { CarBrand mob = new CarBrand(); mob.brand = brand; mob.addedBy = User.Identity.GetUserId(); mob.status = "a"; mob.time = DateTime.UtcNow; db.CarBrands.Add(mob); await db.SaveChangesAsync(); if (model != null && model != "" && model != "undefined") { CarModel mod = new CarModel(); mod.addedBy = User.Identity.GetUserId(); mod.brandId = mob.Id; mod.status = "a"; mod.time = DateTime.UtcNow; mod.model = model; db.CarModels.Add(mod); await db.SaveChangesAsync(); } } else { var isNewModel = db.CarModels.Any(x => x.model.Equals(model)); if (!isNewModel) { if (model != null && model != "" && model != "undefined") { CarModel mod = new CarModel(); mod.addedBy = User.Identity.GetUserId(); mod.brandId = db.CarBrands.First(x => x.brand.Equals(brand)).Id; mod.status = "a"; mod.time = DateTime.UtcNow; mod.model = model; db.CarModels.Add(mod); await db.SaveChangesAsync(); } } } } return(true); }