Esempio n. 1
0
        public ActionResult Create([Bind(Include = "ProductId,ProductName,Price,Comment,ApplicationUserId,CountryId,DistrictId,FileName,CreatedDate,IsDeleted")] Product product, HttpPostedFileBase Photo)
        {
            if (ModelState.IsValid)
            {
                string id = User.Identity.GetUserId();
                product.ApplicationUserId = id;
                WebImage img      = new WebImage(Photo.InputStream);
                FileInfo fotoinfo = new FileInfo(Photo.FileName);
                string   newfoto  = Guid.NewGuid().ToString() + fotoinfo.Extension;
                if (img.Width > 800)
                {
                    img.Resize(800, 350);
                    img.Save("~/Content/Dosyalar/" + newfoto);
                    product.Photo = "/Content/Dosyalar/" + newfoto;
                }


                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CountryId = new SelectList(db.Country, "CountryId", "CountryName", product.CountryId);
            //ViewBag.DistrictId = new SelectList(db.District, "DistrictId", "DistrictName", product.DistrictId);
            return(View(product));
        }
        public IHttpActionResult Putq_Customer_items_2_Jeeves(int id, q_Customer_items_2_Jeeves q_Customer_items_2_Jeeves)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public int Add(T t)
        {
            try
            {
                context.Set <T>().Add(t);
                return(context.SaveChanges());
            }
            catch (DbEntityValidationException e)
            {
                string error = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    foreach (var ve in eve.ValidationErrors)
                    {
                        error += String.Format("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                                               ve.PropertyName,
                                               eve.Entry.CurrentValues.GetValue <object>(ve.PropertyName),
                                               ve.ErrorMessage) + "<br>";
                    }
                }

                Debug.WriteLine(e.Message + "\n" + error);
                return(0);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message + "\n" + e.StackTrace);
                return(0);
            }
        }
        public ActionResult Save(Product p)
        {
            Product p1 = new Product();

            p1.ProductName = p.ProductName;
            p1.category    = db.category.SingleOrDefault <Category>(m => m.CategoryId == p.CategoryId);
            // p1.isprodchecked = false;
            // p1.category = p.category;
            p1.CategoryId = p.CategoryId;
            // p1.CategoryId = p.category.CategoryId;
            if (ModelState.IsValid)
            {
                try
                {
                    db.product.Add(p1);
                    db.SaveChanges();
                    return(RedirectToAction("GetData"));
                }
                catch
                {
                    return(RedirectToAction("Add"));
                }
            }
            else
            {
                ModelState.AddModelError("", "All fields are required");
                return(RedirectToAction("Add"));
            }
        }
        public IHttpActionResult Putq_material_group(short id, q_material_group q_material_group)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != q_material_group.ForetagKod)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult Putxakh(string id, xakh xakh)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != xakh.ArtKat)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 7
0
        public ActionResult Save(Category c)
        {
            Category c1 = new Category();

            c1.CategoryName = c.CategoryName;
            var data = db.category.FirstOrDefault <Category>(m => m.CategoryName == c.CategoryName);

            if (data == null)
            {
                //c1.iscatchecked= false;
                if (ModelState.IsValid)
                {
                    try
                    {
                        db.category.Add(c1);
                        db.SaveChanges();
                        return(RedirectToAction("GetData"));
                    }
                    catch
                    {
                        return(RedirectToAction("Add"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "All fields are required");
                    return(View("Add"));
                }
            }
            else
            {
                return(RedirectToAction("Add"));
            }
        }
Esempio n. 8
0
        public IHttpActionResult PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != product.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 9
0
        public IHttpActionResult stuffinsert(stuff stuffInsert)
        {
            DC.stuffs.Add(stuffInsert);
            DC.SaveChanges();

            return(Ok());
        }
Esempio n. 10
0
        public ActionResult Create([Bind(Include = "ProductId,ProductName,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(product));
        }
Esempio n. 11
0
        public ActionResult Create([Bind(Include = "CustomerId,CardNumber,ExpirationDate,Cvv")] CardData cardData)
        {
            if (ModelState.IsValid)
            {
                db.CardDatas.Add(cardData);
                db.SaveChanges();
                return(RedirectToAction("OrderPlaced"));
            }

            return(View(cardData));
        }
Esempio n. 12
0
        public ActionResult Create([Bind(Include = "foretagkod,lagstalle,q_profit_center,q_material_group,q_isbn_no,artnr,artbeskr,q_itemtypecd1,q_artkat,artlistpris,momskod,itemstatuscode,q_sap_item_no,artstatnr,UpdateStatusDescr,itemtypecd2,q_wsoy_libraryclass,varugruppkod,q_fetched_by_inobiz,ar_q_edition_counter,artkalkber,artkalkpris,q_publisher_itemid,artvikt,q_publ_date,q_artbeskr_kiva,q_planned_arrival_date,q_pl_garr_date,ArtBeskrSpec,q_author,q_edt,q_aof,q_au,q_des,q_eic,q_ill,q_ot,q_pho,q_pre,q_rea,q_tra,itemtypecd3,q_print_year,q_size,q_original_title,q_series,q_series_id,q_series_partno,q_total_no_part_series,itemtypecd4,q_language,webpublish")] q_Customer_items_2_Jeeves q_Customer_items_2_Jeeves)
        {
            if (ModelState.IsValid)
            {
                db.q_Customer_items_2_Jeeves.Add(q_Customer_items_2_Jeeves);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(q_Customer_items_2_Jeeves));
        }
        public ActionResult Create([Bind(Include = "Product_id,Product_name,Rate,Model_id")] Product_tbl product_tbl)
        {
            if (ModelState.IsValid)
            {
                db.Product_tbl.Add(product_tbl);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Model_id = new SelectList(db.ProductDetails, "Model_id", "Model_name", product_tbl.Model_id);
            return(View(product_tbl));
        }
Esempio n. 14
0
        public ActionResult Create(Product model)
        {
            ValidateProduct(model);
            if (ModelState.IsValid)
            {
                db.Products.Add(model);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 15
0
        public TblProductList Add(TblProductList item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            // TO DO : Code to save record into database
            ProductDB.TblProductLists.Add(item);
            ProductDB.SaveChanges();
            return(item);
        }
Esempio n. 16
0
        public IHttpActionResult Create(ProductModel productModel)
        {
            var product = new Table_DB_Product()
            {
                Name  = productModel.Name,
                Price = productModel.Price
            };

            _context.Table_DB_Product.Add(product);
            _context.SaveChanges();
            return(Ok("Success"));
        }
        public HttpResponseMessage Put([FromBody] int id, [FromUri] Product newProduct)
        {
            try
            {
                using (ProductEntities entity = new ProductEntities())
                {
                    Product existingProduct = entity.Products.FirstOrDefault(x => x.ProductId == id);
                    if (existingProduct == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Product with Given Id does not exist!"));
                    }

                    existingProduct.Name     = newProduct.Name;
                    existingProduct.Price    = newProduct.Price;
                    existingProduct.Quantity = newProduct.Quantity;
                    existingProduct.BoxSize  = newProduct.BoxSize;
                    entity.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, existingProduct));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Esempio n. 18
0
        public ProductResponse Delete(ProductRequest request)
        {
            ProductItem item = request.Product;

            var response = new ProductResponse();

            using (var db = new ProductEntities())
            {
                var model = new PRODUCT
                {
                    ID = (int)item.Id
                };

                var entry = db.Entry(model);

                if (entry.State == System.Data.Entity.EntityState.Detached)
                {
                    db.PRODUCTS.Attach(model);
                }

                db.PRODUCTS.Remove(model);
                db.SaveChanges();
            }

            return(response);
        }
Esempio n. 19
0
        public ProductResponse SaveProduct(ProductRequest request)
        {
            ProductItem item     = request.Product;
            var         response = new ProductResponse();

            using (var db = new ProductEntities())
            {
                var model = new PRODUCT
                {
                    NAME        = item.Name,
                    QUANTITY    = item.Quantity,
                    SALE_AMOUNT = item.SaleAmount
                };

                if (item.Id == null)
                {
                    db.PRODUCTS.Add(model);
                }
                else
                {
                    model.ID = (int)item.Id;
                    db.Entry(model).State = System.Data.Entity.EntityState.Modified;
                }

                db.SaveChanges();
            }

            return(response);
        }
Esempio n. 20
0
        private static void SaveProducts(List <Product> newProductsList)
        {
            ProductEntities db = new ProductEntities();

            //Remove the exiting records.
            var allProducts = db.Products.ToList();

            if (allProducts.Count > 0)
            {
                db.Products.RemoveRange(allProducts);
                db.SaveChanges();
            }

            db.Products.AddRange(newProductsList);

            db.SaveChanges();
        }
Esempio n. 21
0
 public bool InsertProduct(string name, float price, int quantity)
 {
     try
     {
         Product product = new Product();
         product.Name     = name;
         product.Price    = price;
         product.Quantity = quantity;
         db.Products.Add(product);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 22
0
        public IHttpActionResult Post([FromBody] Product reuest)
        {
            string result = string.Empty;

            try
            {
                dbContext.Products.Add(reuest);
                dbContext.SaveChanges();
                result = "Record inserted successfully.";
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }

            return(Ok(result));
        }
Esempio n. 23
0
 public bool DeleteProduct(int id)
 {
     try
     {
         var product = db.Products.Where(x => x.Id == id).FirstOrDefault();
         if (product == null)
         {
             return(false);
         }
         db.Entry(product).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
 public bool Delete(int id)
 {
     //new NotImplementedException(); customers
     try
     {
         var customer = db.Customers.Where(x => x.id == id).FirstOrDefault();
         if (customer == null)
         {
             return(false);
         }
         db.Entry(customer).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Esempio n. 25
0
 public ActionResult SaveProduct(ProductViewModel model)
 {
     if (ModelState.IsValid)
     {
         Product product = new Product();
         product.CategoryId  = model.Category;
         product.Description = model.Description;
         product.Name        = model.Name;
         product.Price       = model.Price.Value;
         product.Quantity    = model.Quantity.Value;
         dbContext.Products.Add(product);
         dbContext.SaveChanges();
         return(Json(new { success = true }));
     }
     else
     {
         return(Json(new { success = false }));
     }
 }
Esempio n. 26
0
        public IHttpActionResult AddCategory(Category cat)
        {
            using (var ctx = new ProductEntities())
            {
                ctx.Categorys.Add(cat);
                ctx.SaveChanges();

                var result = ctx.Categorys.ToList();
                return(Ok(result));
            }
        }
Esempio n. 27
0
        public void AddNewProduct(ProductTable product)
        {
            ProductEntities entities = new ProductEntities();

            if (product == null)
            {
                throw new Exception("Product details are not set");
            }
            entities.ProductTables.Add(product);
            entities.SaveChanges();
        }
Esempio n. 28
0
 public bool Delete(String Id)
 {
     //throw new NotImplementedException();
     //throw new NotImplementedException();s
     try
     {
         var product = db.Products.Where(x => x.id == Id).FirstOrDefault();
         if (product == null)
         {
             return(false);
         }
         db.Entry(product).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
Esempio n. 29
0
        public IHttpActionResult Add(string name, int category, int price)
        {
            using (var ctx = new ProductEntities())
            {
                ctx.Products.Add(new Product {
                    Name = name, CategoryId = category, Price = price
                });
                ctx.SaveChanges();

                return(Ok(ctx.Products.Include("Category").ToList()));
            }
        }
Esempio n. 30
0
        public IHttpActionResult RemoveProduct(int id)
        {
            using (var ctx = new ProductEntities())
            {
                var product = ctx.Products.FirstOrDefault((x) => x.Id == id);

                ctx.Products.Remove(product);
                ctx.SaveChanges();

                return(Ok(ctx.Products.Include("Category").ToList()));
            }
        }