public string Update(int id, string name, decimal price, HttpPostedFileBase imageurl, string itemdesc, int catid, string available)
        {
            if (imageurl == null)
            {
                return("Please select an image!");
            }

            //set new upload location
            string location = Server.MapPath("~/Content/Images/");

            //generate folder if it doessnt exist
            if (!Directory.Exists(location))
            {
                Directory.CreateDirectory(location);
            }

            //get file name
            var fileName = Path.GetFileName(imageurl.FileName);

            //get file extension
            string extension = Path.GetExtension(imageurl.FileName);

            //create unique file name
            string uniquefilename = Guid.NewGuid().ToString("N") + extension;

            //Combine location with image
            string fileinpath = Path.Combine(location + uniquefilename);

            //Store image
            imageurl.SaveAs(fileinpath);

            string dbpath = "/Content/Images/" + uniquefilename;


            ShopMgtSystemDBContext db = new ShopMgtSystemDBContext();
            Item item = db.Items.Where(a => a.ID == id).FirstOrDefault();



            item.Name            = name;
            item.Price           = price;
            item.ImageURL        = dbpath;
            item.ItemDescription = itemdesc;
            item.CategoryID      = catid;
            item.Availability    = available;



            int count = db.SaveChanges();

            if (count > 0)
            {
                return("1");
            }
            else
            {
                return("An error occured. Please try again.");
            }
        }
        public string Delete(int id)
        {
            ShopMgtSystemDBContext db = new ShopMgtSystemDBContext();
            Item item = db.Items.Where(a => a.ID == id).FirstOrDefault();

            db.Items.Remove(item);
            int count = db.SaveChanges();

            if (count > 0)
            {
                return("You have deleted this item. Click 'OK' to continue...");
            }
            else
            {
                return("An error occured. Try again.");
            }
        }
Exemple #3
0
        public string Delete(int id)
        {
            ShopMgtSystemDBContext db = new ShopMgtSystemDBContext();
            var del = db.Categories.Where(a => a.ID == id).FirstOrDefault();

            db.Categories.Remove(del);
            int count = db.SaveChanges();

            if (count > 0)
            {
                return("Deleted Successfully! Press 'OK' to continue...");
            }
            else
            {
                return("An error occured!");
            }
        }
Exemple #4
0
        public string Update(string cname, int id)
        {
            ShopMgtSystemDBContext db = new ShopMgtSystemDBContext();
            Category cat = db.Categories.Where(a => a.ID == id).FirstOrDefault();

            cat.CategoryName = cname;


            int count = db.SaveChanges();

            if (count > 0)
            {
                return("Updated Successfully! Press 'OK' to continue...");
            }
            else
            {
                return("An error occurred!");
            }
        }
Exemple #5
0
        public string AddCategories(string cname)
        {
            ShopMgtSystemDBContext db = new ShopMgtSystemDBContext();
            Category category         = new Category();

            category.CategoryName = cname;

            db.Categories.Add(category);

            int count = db.SaveChanges();

            if (count > 0)
            {
                return("You have added a new category.");
            }
            else
            {
                return("An error occured.");
            }
        }