public IHttpActionResult PutBRAND(int id, BRAND bRAND) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != bRAND.ID_BRAND) { return(BadRequest()); } db.Entry(bRAND).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BRANDExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public List <BRAND> Search(BRAND Brand, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, SortDirection SortDirection) { var result = Context.BRAND.AsQueryable(); if (Brand != null) { if (!String.IsNullOrEmpty(Brand.Name)) { result = result.Where(b => b.Name.Contains(Brand.Name)); } if (!String.IsNullOrEmpty(Brand.ShowName)) { result = result.Where(b => b.ShowName.Contains(Brand.ShowName)); } if (!String.IsNullOrEmpty(Brand.Description)) { result = result.Where(b => b.Description.Contains(Brand.Description)); } if (!String.IsNullOrEmpty(Brand.Email)) { result = result.Where(b => b.Email.Contains(Brand.Email)); } } TotalRecords = result.Count(); GenericSorterCaller <BRAND> sorter = new GenericSorterCaller <BRAND>(); result = sorter.Sort(result, string.IsNullOrEmpty(OrderExp) ? DEFAULT_ORDER_EXP : OrderExp, SortDirection); // pagination return(result.Skip(PageIndex * PageSize).Take(PageSize).ToList()); }
public bool insertBrand(BRAND entity) { bool check = false; int maTH = 1; while (!check) { if (maTH < 10) { entity.MaTH = "TH0" + maTH.ToString(); } else { entity.MaTH = "TH" + maTH.ToString(); } try { db.BRANDs.Add(entity); db.SaveChanges(); check = true; return(true); } catch { } maTH++; } return(false); }
public ActionResult Edit(BRAND brand, HttpPostedFileBase file) { if (Session["Account"] == null) { return(RedirectToAction("Index", "Login", new { area = "" })); } else { if (ModelState.IsValid) { if (file != null && file.ContentLength > 0) { string filename = System.IO.Path.GetFileName(file.FileName); string urlfile = Server.MapPath("~/Images/" + filename); file.SaveAs(urlfile); brand.HinhAnh = "/Images/" + filename; } var th = new BrandModel(); bool res = th.updateBrand(brand); if (res) { return(RedirectToAction("Edit", "Brand", new { maTH = brand.MaTH, type = "success" })); } } return(View(brand)); } }
public ActionResult Insert(BRAND entity, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null && file.ContentLength > 0) { string filename = System.IO.Path.GetFileName(file.FileName); string urlfile = Server.MapPath("~/Images/" + filename); file.SaveAs(urlfile); entity.HinhAnh = "/Images/" + filename; } var th = new BrandModel(); bool res = th.insertBrand(entity); if (res) { return(RedirectToAction("Insert", "Brand", new { type = "success" })); } else { return(RedirectToAction("Insert", "Brand", new { type = "fail" })); } } return(View(entity)); }
public ActionResult DeleteConfirmed(int id) { BRAND bRAND = db.BRANDs.Find(id); db.BRANDs.Remove(bRAND); db.SaveChanges(); return(RedirectToAction("Index")); }
public void DeleteById(int id) { BRAND obj = new BRAND() { ID = id }; Delete(obj); }
public Brand(BRAND entity = null) { if (entity == null) { return; } Id = entity.ID; Name = entity.NAME; }
public ActionResult Edit([Bind(Include = "ID,BRAND1")] BRAND bRAND) { if (ModelState.IsValid) { db.Entry(bRAND).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bRAND)); }
public IHttpActionResult GetBRAND(int id) { BRAND bRAND = db.BRAND.Find(id); if (bRAND == null) { return(NotFound()); } return(Ok(bRAND)); }
public async Task <ActionResult> CreateBrand(BRAND model) { if (ModelState.IsValid) { model.BrandURL = SlugGenerator.SlugGenerator.GenerateSlug(model.BrandName); model.CreatedDate = DateTime.Now; int result = await new BrandDAO().CreateBrand(model); return(RedirectToAction("CreateBrand")); } return(View()); }
public ActionResult Create([Bind(Include = "ID,BRAND1")] BRAND bRAND) { if (ModelState.IsValid) { db.BRANDs.Add(bRAND); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bRAND)); }
public IHttpActionResult PostBRAND(BRAND bRAND) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.BRAND.Add(bRAND); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = bRAND.ID_BRAND }, bRAND)); }
internal static bool CheckIfNameExist(BRAND brand) { using (IDalBrand dal = new DalBrand()) { bool result = false; List <string> nameList = dal.GetAllBrand().Select(n => n.nameBrand.ToLower()).ToList(); if (nameList.Contains(brand.nameBrand.ToLower())) { result = true; } return(result); } }
// GET: BRAND/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BRAND bRAND = db.BRANDs.Find(id); if (bRAND == null) { return(HttpNotFound()); } return(View(bRAND)); }
public IHttpActionResult DeleteBRAND(int id) { BRAND bRAND = db.BRAND.Find(id); if (bRAND == null) { return(NotFound()); } db.BRAND.Remove(bRAND); db.SaveChanges(); return(Ok(bRAND)); }
public CARD(int id, string ip, int ax_num, int input_num, int output_num, BRAND brand, TYPE type, string disc, string ps = "") { this.m_id = id; this.ip = ip; this.ax_num = ax_num; this.input_num = input_num; this.output_num = output_num; this.brand = brand; this.type = type; this.ps = ps; isInit = false; handle = (IntPtr)0; str_disc = disc; }
public async Task <int> CreateBrand(BRAND cate) { try { db.BRANDs.Add(cate); await db.SaveChangesAsync(); return(cate.BrandID); } catch { return(0); } }
public async Task <JsonResult> EditBrand(BRAND model, int id) { if (ModelState.IsValid) { model.BrandURL = SlugGenerator.SlugGenerator.GenerateSlug(model.BrandName); int result = await new BrandDAO().EditBrand(model, id); if (result == 0) { return(Json(new { Success = false, id }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, id }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = false, id }, JsonRequestBehavior.AllowGet)); }
public long Brandadd(BRAND entity) { var result = db.BRANDs.Count(x => x.brandName == entity.brandName); if (result > 0) { return(0); } else { db.BRANDs.Add(entity); db.SaveChanges(); return(entity.brandId); } }
public CARD(int id, string port_name, int baudrate, BRAND brand, TYPE type, string disc, string ps = "") { this.m_id = id; this.ax_num = 10000; this.input_num = 10000; this.output_num = 10000; this.brand = brand; this.type = type; this.ps = ps; isInit = false; handle = (IntPtr)0; str_disc = disc; PortName = port_name; Baudrate = baudrate; }
public bool UpdateBrand(BRAND entity, int id) { try// su ly ngoai le { var update = db.BRANDs.Find(id); update.brandName = entity.brandName; update.topBrand = entity.topBrand; db.Entry(update).State = EntityState.Modified; db.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
protected void btnSave_Click(object sender, EventArgs e) { if (IsValid) { //Save Brand BRAND br = new BRAND(); br.Name = txtName.Text; br.ShowName = txtShowName.Text; br.Website = txt_web.Text; br.Telephone = txt_tel.Text; br.Email = txtEmail.Text; br.Description = txtDesc.Text; br.Contact = txt_contact.Text; br.Shop = chkShop.Checked; br.Address = txtAddress.Text; int id = 0; lblErrors.Visible = true; lblErrors.ForeColor = Color.Green; string operation = String.Empty; try { if (!String.IsNullOrWhiteSpace(ID.Value) && Int32.TryParse(ID.Value, out id) && id != 0) { br.ID = id; ApplicationContext.Current.Brands.Update(br); operation = "updated"; } else { ApplicationContext.Current.Brands.Insert(br); operation = "inserted"; ID.Value = br.ID.ToString(); } lblErrors.Text = "Brand " + operation + " correctly."; } catch (Exception ex) { // TODO log error lblErrors.ForeColor = Color.Red; lblErrors.Text = "Error occurred: " + ex.Message; } } }
public bool updateBrand(BRAND entity) { object[] sqlparams = { new SqlParameter("@MaTH", entity.MaTH), new SqlParameter("@TenTH", entity.TenTH), new SqlParameter("@DiaChi", entity.DiaChiTH), new SqlParameter("@SDT", entity.SDT), new SqlParameter("@HinhAnh", entity.HinhAnh), }; try { db.Database.ExecuteSqlCommand("SuaBRAND @MaTH,@TenTH,@DiaChi,@SDT,@HinhAnh", sqlparams); return(true); } catch { } return(false); }
public async Task <JsonResult> UpdateBrand(BRAND model, int id) { var json = JsonConvert.SerializeObject(model); var data = new StringContent(json, Encoding.UTF8, "application/json"); string url = GlobalVariable.url + "api/brand/update?id=" + id; try { var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AdminController.AdminToken); client.BaseAddress = new Uri(url); var response = await client.PutAsync(url, data); if (response.IsSuccessStatusCode) { return(Json(new JsonStatus() { Status = true, Message = "Update Success", StatusCode = (int)response.StatusCode }, JsonRequestBehavior.AllowGet)); } else { return(Json(new JsonStatus() { Status = false, Message = await response.Content.ReadAsStringAsync(), StatusCode = (int)response.StatusCode }, JsonRequestBehavior.AllowGet)); } } catch { return(Json(new JsonStatus() { Status = false, Message = "Error while updating brand", StatusCode = 0 }, JsonRequestBehavior.AllowGet)); } }
protected void Page_Load(object sender, EventArgs e) { Page.Error += new EventHandler(Page_Error); string idBrand = Request["ID"]; int id; //bool result = Int32.TryParse(idBrand, out id); if (!IsPostBack) { BRAND br = null; if (!String.IsNullOrWhiteSpace(idBrand) && Int32.TryParse(idBrand, out id) && id != 0) { br = getBrand(id); ID.Value = id.ToString(); } } }
private BRAND getBrand(int Id) { BRAND brand = null; brand = ApplicationContext.Current.Brands.GetById(Id); if (brand != null) { txtName.Text = brand.Name; txtShowName.Text = brand.ShowName; txt_web.Text = brand.Website; txt_tel.Text = brand.Telephone; txtEmail.Text = brand.Email; txtDesc.Text = brand.Description; txt_contact.Text = brand.Contact; chkShop.Checked = brand.Shop.HasValue ? brand.Shop.Value : false; txtAddress.Text = brand.Address; } return(brand); }
public async Task <IHttpActionResult> UpdateBrand(int id, BRAND brand) { if (!ModelState.IsValid) { return(Content(HttpStatusCode.BadRequest, "Not invalid model")); } try { int result = await new BrandDAO().UpdateBrand(id, brand); if (result == 0) { return(Content(HttpStatusCode.Conflict, "Not updated")); } return(Ok()); } catch { return(Content(HttpStatusCode.BadRequest, "Update Fail")); } }
public async Task <int> UpdateBrand(int ID, BRAND brand) { try { var item = db.BRANDs.Find(ID); if (item == null) { return(0); } item.BrandName = brand.BrandName; item.BrandURL = SlugGenerator.SlugGenerator.GenerateSlug(brand.BrandName); await db.SaveChangesAsync(); return(item.BrandID); } catch { return(0); } }
public async Task <int> EditBrand(BRAND cate, int ID) { try { var item = db.BRANDs.Find(ID); if (item == null) { return(0); } item.BrandName = cate.BrandName; item.BrandURL = cate.BrandURL; await db.SaveChangesAsync(); return(item.BrandID); } catch { return(0); } }