public ActionResult Index() { Models.Home home = new Models.Home(); using (var context = new BanDoDienTuEntities()) { var feature = from sp in context.SanPhams join lsp in context.LoaiSanPhams on sp.MaLoai equals lsp.MaLoai where lsp.TenLoai == "mới nhập" select new Models.Product { MaSP = sp.MaSP, TenSP = sp.TenSP, DonGia = sp.GiaBan, Hinh = sp.Hinh }; home.FeaturePhone = feature.Take(6).ToList(); //đếm số lượng sản phẩm List <Models.BrandHome> li = new List <Models.BrandHome>(); Models.Brand brand = new Models.Brand(); List <Models.Brand> b = brand.GetBrand(); foreach (Models.Brand item in b) { Models.BrandHome brh = new Models.BrandHome(); brh.MaNSX = item.MaNSX; brh.TenNSX = item.TenNSX; var h = from sp in context.SanPhams join nsx in context.NhaSanXuats on sp.MaNSX equals nsx.MaNSX where nsx.TenNSX == item.TenNSX select new Models.Product { }; brh.SoLuong = h.Count(); li.Add(brh); } home.brand = li; } return(View(home)); }
public async Task <IActionResult> Brand(string id) { Models.Brand vm = new Models.Brand(); if (id != null) { //existing recored using (var httpClient = new HttpClient()) { string url = baseAddress + "brands/" + id + ".json"; using (var response = await httpClient.GetAsync(url)) { if (response.StatusCode == HttpStatusCode.OK) { string apiResponse = await response.Content.ReadAsStringAsync(); vm = JsonConvert.DeserializeObject <Models.Brand>(apiResponse); } } } ViewBag.ItemId = id; } return(View(vm)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } try { brand = await _context.Brands.Where(m => m.Id == id).FirstOrDefaultAsync(); if (brand == null) { return(NotFound()); } return(Page()); } catch (Exception ex) { //With this code, we save in log files what we want. _log.LogError(ex.Message + ". ID : {0}", id); TempData["ErrorMessage"] = ex.Message; return(RedirectToPage("Error")); } }
public ActionResult Delete(int id, FormCollection collection) { var db = new Models.Database1Entities(); Models.Brand brand = db.Brand.Find(id); db.Brand.Remove(brand); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Delete(int?id) { var db = new Models.Database1Entities(); Models.Brand brand = db.Brand.Find(id); if (brand == null) { return(HttpNotFound()); } return(View(brand)); }
public ActionResult Edit([Bind(Include = "Id_brand,name")] Models.Brand brand) { var db = new Models.Database1Entities(); if (ModelState.IsValid) { db.Entry(brand).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
public ActionResult Create(Models.Brand brand) { var db = new Models.Database1Entities(); if (ModelState.IsValid) { db.Brand.Add(brand); db.SaveChanges(); return(this.RedirectToAction("Index")); } return(this.View(brand)); }
public ActionResult AddBrand(Models.Brand brand) { if (ModelState.IsValid) { Entity.Brand brandDetails = new Entity.Brand() { BrandName = brand.BrandName, }; mobileBL.AddBrand(brandDetails); return(RedirectToAction("Create")); } return(View()); }
public async Task <IActionResult> Brand(Models.Brand vm, string id) { if (id != null) { //existing record using (var httpClient = new HttpClient()) { var json = JsonConvert.SerializeObject(vm); var data = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json"); string url = baseAddress + "brands/" + id + ".json"; using (var response = await httpClient.PutAsync((url), data)) { if (response.StatusCode == HttpStatusCode.OK) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Error", "Home")); } } } } else { using (var httpClient = new HttpClient()) { var json = JsonConvert.SerializeObject(vm); var data = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json"); string url = baseAddress + "brands.json"; using (var response = await httpClient.PostAsync((url), data)) { if (response.StatusCode == HttpStatusCode.OK) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Error", "Home")); } } } } }
void ImportBrands(Data data) { foreach (var brandData in data.Brands) { var brand = _context.Brands.SingleOrDefault(b => b.LinkName == brandData.LinkName); if (brand == null) { brand = new Models.Brand(); _context.Brands.Add(brand); } brand.LinkName = brandData.LinkName; brand.Name = brandData.Name; _context.SaveChanges(); } }
public ActionResult Edit(int?id) { var db = new Models.Database1Entities(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.Brand magazine = db.Brand.Find(id); if (magazine == null) { return(HttpNotFound()); } return(View(magazine)); }
//Updates the existing Brand Details public async Task <IActionResult> OnPutUpdateBrand([FromBody] Models.Brand obj) { if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Manager"))) { try { _context.Attach(obj).State = EntityState.Modified; await _context.SaveChangesAsync(); return(new JsonResult(obj)); } catch (DbUpdateException d) { return(new JsonResult("Brand Changes not saved." + d.InnerException.Message)); } } return(new JsonResult("Brand Changes not saved. You do not have access rights to save these changes")); }
public async Task <IActionResult> OnPostDeleteAsync(string deleteId) { int id = 0; if (!int.TryParse(deleteId, out id)) { throw new Exception("Wrong Id Information."); } try { Models.Brand brand = await _context.Brands.Where(m => m.Id == id).FirstOrDefaultAsync(); if (brand == null) { return(NotFound()); } if ((brand.Products != null && brand.Products.Count != 0) || (brand.BrandModels != null && brand.BrandModels.Count != 0)) { throw new Exception("There are related Records with this Brand. First You have to delete them!"); } _context.Brands.Remove(brand); //With this code, we save the entity history. _context.EnsureAutoHistory(); await _context.SaveChangesAsync(); //With this code, we save in log files what we want. _log.LogInformation("Record Deleted"); return(RedirectToPage("Index", new { messageType = MessageType.Delete })); } catch (Exception ex) { //With this code, we save in log files what we want. _log.LogError(ex.Message + ". ID : {0}", id); TempData["ErrorMessage"] = ex.Message; return(RedirectToPage("Error")); } }
protected override void Seed(WebApplication2.Models.AutosContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. var audi = new Models.Brand() { Name = "AUDI", Country = "Germany" }; var fiat = new Models.Brand() { Name = "FIAT", Country = "Italy" }; context.Brands.Add(audi); context.Brands.Add(fiat); context.SaveChanges(); context.Cars.Add(new Models.Car() { Name = "A3", Price = 34567, BrandId = audi.Id }); context.Cars.Add(new Models.Car() { Name = "A4", Price = 45678, BrandId = audi.Id }); context.Cars.Add(new Models.Car() { Name = "500", Price = 12345, BrandId = fiat.Id }); context.Cars.Add(new Models.Car() { Name = "Punto", Price = 23456, BrandId = fiat.Id }); context.SaveChanges(); }
//Inserts a new Brand with details public async Task <IActionResult> OnPostInsertBrand([FromBody] Models.Brand obj) { if (obj != null && (HttpContext.User.IsInRole("Admin") || HttpContext.User.IsInRole("Fleet"))) { try { _context.Add(obj); await _context.SaveChangesAsync(); int id = obj.BrandID; // Yes it's here return(new JsonResult(obj)); } catch (DbUpdateException d) { return(new JsonResult("Brand Not Added." + d.InnerException.Message)); } } else { return(new JsonResult("Brand Not Inserted")); } }
public Brand Create(Models.Brand obj) { obj.ID = 3000; return(obj); }
public Models.Brand Update(Models.Brand obj) { return(obj); }
//brand #region public ActionResult Brand(int page = 1) { Models.Brand listbrand = new Models.Brand(); return(View(listbrand.GetBrand().ToPagedList(page, 2))); }
public IActionResult OnGet() { brand = new Models.Brand(); return(Page()); }
public ActionResult UpdateBrand(int id) { Models.Brand updatebrand = new Models.Brand(); return(View(updatebrand.GetBrandByID(id))); }