Exemple #1
0
        public IHttpActionResult PutCATEGORy(string id, CATEGORy cATEGORy)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != cATEGORy.MA_DANH_MUC)
            {
                return(BadRequest());
            }

            db.Entry(cATEGORy).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CATEGORyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public void Delete(int id)
        {
            CATEGORy cat = db.CATEGORIES.Find(id);

            db.CATEGORIES.Remove(cat);
            SaveChanges();
        }
Exemple #3
0
        public IHttpActionResult PostCATEGORy(CATEGORy cATEGORy)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CATEGORIES.Add(cATEGORy);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CATEGORyExists(cATEGORy.MA_DANH_MUC))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = cATEGORy.MA_DANH_MUC }, cATEGORy));
        }
        public ActionResult Edit(int id)
        {
            ViewBag.ListCategories = categoriesModels.GetAllItem();
            CATEGORy Category = categoriesModels.GetItem(id);

            return(View(Category));
        }
 public ActionResult Update(FormCollection f)
 {
     try
     {
         int      id        = int.Parse(f.Get("ID").ToString());
         string   name      = f.Get("NAME").ToString();
         CATEGORy _CATEGORY = db.CATEGORIES.Find(id);
         List <CATEGORIES_BY_SUPPLIER> _lstCATEGORY = db.CATEGORIES_BY_SUPPLIER.Where(n => n.CATEGORY_ID == id).ToList();
         foreach (var category in _lstCATEGORY)
         {
             category.CATEGORY_NAME = name;
             db.SaveChanges();
         }
         _CATEGORY.CATEGORY_NAME = name;
         db.SaveChanges();
         if (_CATEGORY.IS_ACCESSORY == true)
         {
             return(RedirectToAction("ManagingAccesstories", "Admin"));
         }
         else
         {
             return(RedirectToAction("ManagingCategories", "Admin"));
         }
     }
     catch (Exception ex)
     {
         return(RedirectToAction("Http404", "Error")); // 404
     }
 }
Exemple #6
0
        public async Task <bool> SaveCategory(Category model)
        {
            var category = context.CATEGORIES.FirstOrDefault(x => x.ID == model.ID);

            if (category == null)
            {
                category = new CATEGORy {
                    SYNONYMS = model.SYNONYMS, NAME = model.NAME, CREATEDON = DateTime.Now, STATUS = "Active", IMAGEURL = model.IMAGEURL, PRODUCTS = 0, SUBCATEGORIES = 0
                };
                context.CATEGORIES.Add(category);
            }

            try
            {
                await context.SaveChangesAsync();

                model.ID        = category.ID;
                model.CREATEDON = category.CREATEDON;
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CATEGORy cATEGORY = db.CATEGORIES.Find(id);

            db.CATEGORIES.Remove(cATEGORY);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "categoryID,categoryName,workstreamID")] CATEGORy cATEGORY)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cATEGORY).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.workstreamID = new SelectList(db.WORKSTREAMS, "workstreamID", "workstreamName", cATEGORY.workstreamID);
     return(View(cATEGORY));
 }
Exemple #9
0
        public IHttpActionResult GetCATEGORy(string id)
        {
            CATEGORy cATEGORy = db.CATEGORIES.Find(id);

            if (cATEGORy == null)
            {
                return(NotFound());
            }

            return(Ok(cATEGORy));
        }
        public ActionResult Create([Bind(Include = "categoryID,categoryName,workstreamID")] CATEGORy cATEGORY)
        {
            if (ModelState.IsValid)
            {
                db.CATEGORIES.Add(cATEGORY);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.workstreamID = new SelectList(db.WORKSTREAMS, "workstreamID", "workstreamName", cATEGORY.workstreamID);
            return(View(cATEGORY));
        }
        public int  GetByName(CATEGORy cat)
        {
            var val = db.CATEGORIES.Where(x => x.CATNAME == cat.CATNAME && x.CAT_STATUS == cat.CAT_STATUS).FirstOrDefault();

            if (val != null)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CATEGORy cATEGORY = db.CATEGORIES.Find(id);

            if (cATEGORY == null)
            {
                return(HttpNotFound());
            }
            return(View(cATEGORY));
        }
Exemple #13
0
        public IHttpActionResult DeleteCATEGORy(string id)
        {
            CATEGORy cATEGORy = db.CATEGORIES.Find(id);

            if (cATEGORy == null)
            {
                return(NotFound());
            }

            db.CATEGORIES.Remove(cATEGORy);
            db.SaveChanges();

            return(Ok(cATEGORy));
        }
 public HttpResponseMessage AddNewCategory(CATEGORy category)
 {
     try
     {
         var commonService = new CommonService();
         var id            = commonService.AddNewCategory(category);
         var response      = Request.CreateResponse(HttpStatusCode.OK, id);
         return(response);
     }
     catch (Exception e)
     {
         var error = Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message);
         return(error);
     }
 }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CATEGORy cATEGORY = db.CATEGORIES.Find(id);

            if (cATEGORY == null)
            {
                return(HttpNotFound());
            }
            ViewBag.workstreamID = new SelectList(db.WORKSTREAMS, "workstreamID", "workstreamName", cATEGORY.workstreamID);
            return(View(cATEGORY));
        }
Exemple #16
0
        public ActionResult Login(CATEGORy cat)
        {
            int x = _objCATBs.GetByName(cat);

            if (x == 1)
            {
                return(RedirectToAction("Login"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }

            // return View();
        }
Exemple #17
0
        public int DeleteItem(int id)
        {
            POST Post = db.POSTs.Where(c => c.ID_CATEGORY == id).FirstOrDefault();

            if (Post != null)
            {
                return(-1);
            }
            CATEGORy Category = db.CATEGORIES.Where(c => c.ID_PARENT == id).FirstOrDefault();

            if (Category != null)
            {
                return(-1);
            }
            db.CATEGORIES.Remove(db.CATEGORIES.Find(id));
            return(db.SaveChanges());
        }
        // =========================================== INSERT =============================================
        public void Insert(string data1)
        {
            CATEGORy call = new CATEGORy();

            {
                call.NAME = data1;
            };
            try
            {
                context.CATEGORIES.Add(call);
                var result = context.SaveChanges();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                System.Console.Write(ex.InnerException);
            }
        }
Exemple #19
0
 public int AddItem(CATEGORy Category)
 {
     using (DbContextTransaction transaction = db.Database.BeginTransaction())
     {
         try
         {
             Category.URL_SLUG = ConvertString.ToUrlSlug(Category.NAME);
             db.CATEGORIES.Add(Category);
             int i = db.SaveChanges();
             transaction.Commit();
             return(Category.ID);
         }
         catch
         {
             transaction.Rollback();
             return(0);
         }
     }
 }
        public ActionResult Edit(int id, CATEGORy Category)
        {
            if (ModelState.IsValid)
            {
                int idCate = categoriesModels.EditItem(id, Category);
                if (idCate > 0)
                {
                    Session["mes"] = "Sửa thành công";
                }
                else
                {
                    Session["mes_er"] = "Sửa thất bại";
                }
                return(RedirectToAction("Index", "CategoriesManager"));
            }

            ViewBag.ListCategories = categoriesModels.GetAllItem();
            return(View(Category));
        }
Exemple #21
0
        /// <summary>
        /// Add new product/ service category
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        public Guid AddNewCategory(CATEGORy category)
        {
            try
            {
                if (category == null)
                {
                    throw new ArgumentNullException("Category", "Category can not be null");
                }

                // check if all required fields are present
                if (category.NAME == null || !category.SERVICE.HasValue)
                {
                    throw new ArgumentException("Category", "Some mandatory parameters required to add a new category are missing");
                }

                if (!category.ID.HasValue || category.ID.Value == Guid.Empty)
                {
                    category.ID = Guid.NewGuid();
                }

                using (APIShopKaro.Models.apsteamCFHEntities db = new APIShopKaro.Models.apsteamCFHEntities())
                {
                    try
                    {
                        db.CATEGORIES.Add(category);
                        db.SaveChanges();
                    }
                    catch (System.Data.DataException e)
                    {
                        throw new Exception(e.InnerException.InnerException.Message);
                    }
                }

                return(category.ID.Value);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Exemple #22
0
        public int EditItem(int id, CATEGORy Category)
        {
            CATEGORy CategoryEdit = db.CATEGORIES.Find(id);

            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    CategoryEdit.NAME            = Category.NAME;
                    CategoryEdit.URL_SLUG        = ConvertString.ToUrlSlug(Category.NAME);
                    CategoryEdit.DESCRIPTION     = Category.DESCRIPTION;
                    CategoryEdit.ID_PARENT       = Category.ID_PARENT;
                    db.Entry(CategoryEdit).State = EntityState.Modified;
                    int i = db.SaveChanges();
                    transaction.Commit();
                    return(CategoryEdit.ID);
                }
                catch
                {
                    transaction.Rollback();
                    return(0);
                }
            }
        }
 public int GetByName(CATEGORy cat)
 {
     return(_objDAL.GetByName(cat));
 }
 public void Insert(CATEGORy cat)
 {
     _objDAL.Insert(cat);
 }
 public void Update(CATEGORy cat)
 {
     _objDAL.Update(cat);
 }
 public void Insert(CATEGORy cat)
 {
     db.CATEGORIES.Add(cat);
     SaveChanges();
 }
 public void Update(CATEGORy cat)
 {
     db.Entry(cat).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }