Example #1
0
 public JsonResult CategoryEdit(int id, string name)
 {
     try
     {
         Models.Category model = db.Categories.Single(m => m.CategoryID == id);
         model.Name            = name;
         db.Entry(model).State = EntityState.Modified;
         db.SaveChanges();
         return(Json(1));
     }
     catch
     {
         return(Json(0));
     }
 }
Example #2
0
        public IHttpActionResult PutCategory(int id, Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #3
0
        public virtual ActionResult Delete(long id)
        {
            try
            {
                using (var db = new MarketContext())
                {
                    var models = db.Set <T>();
                    var model  = models.Find(id);

                    if (model == null)
                    {
                        throw new Exception("رکورد با ایدی داده شد یافت نشد");
                    }

                    db.Entry(model).State = EntityState.Deleted;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(RedirectToAction("Images"));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                return(PartialView("Error", e));
            }
        }
Example #4
0
        public async Task <IActionResult> PutProduct(long id, Product product)
        {
            if (id != product.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult Edit([Bind(Include = "ProductID,Title,Description,Price,CreatedDate,Status,Delivery")] Product product, HttpPostedFileBase file)
        {
            var productToUpdate = db.Products.Find(product.ProductID);

            if (productToUpdate.Seller.ID.ToString().Equals(SessionContainer.UserID) || SessionContainer.Role.ToString().Equals("1"))
            {
                if (file != null)
                {
                    var dir_path  = Server.MapPath("/Images/" + "\\");
                    var site_path = "/Images/";
                    var file_name = file.FileName;
                    var path      = dir_path + file_name;
                    file.SaveAs(path);

                    if (ModelState.IsValid)
                    {
                        productToUpdate.Image = site_path + file_name;
                    }
                }
                productToUpdate.Category        = product.Category;
                productToUpdate.Title           = product.Title;
                productToUpdate.Description     = product.Description;
                productToUpdate.Price           = product.Price;
                productToUpdate.CreatedDate     = product.CreatedDate;
                productToUpdate.Delivery        = product.Delivery;
                productToUpdate.Status          = product.Status;
                db.Entry(productToUpdate).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
Example #6
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #7
0
        public IHttpActionResult PutItem(long id, Item item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #8
0
 public ActionResult Edit([Bind(Include = "ID,Name,Price,Picture,Category")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
 public ActionResult Edit([Bind(Include = "DocumentTypeID,Description")] DocumentType documentType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(documentType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(documentType));
 }
Example #10
0
 public ActionResult Edit([Bind(Include = "CategoryId,CategoryName")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Example #11
0
 public ActionResult Edit([Bind(Include = "SupplierID,Name,ContactFirstName,ContactLastName,Phone,Address,Email")] Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplier));
 }
 public ActionResult Edit([Bind(Include = "ProductID,Description,Price,LastBuy,Stock,Remarks")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
Example #13
0
 public ActionResult Edit([Bind(Include = "TrademarkID,Name,State")] Trademark trademark)
 {
     if (ModelState.IsValid)
     {
         db.Entry(trademark).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(trademark));
 }
Example #14
0
 public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,Age")] Driver driver)
 {
     if (ModelState.IsValid)
     {
         db.Entry(driver).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(driver));
 }
Example #15
0
 public ActionResult Edit([Bind(Include = "EmployeeID,firstName,lastName,Salary,bonusPercent,DateOfBirth,StartTime,Email,URL,DocumentTypeID,DocumentNumber")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Description", employee.DocumentTypeID);
     return(View(employee));
 }
 public ActionResult Edit([Bind(Include = "CustomerID,FirstName,LastName,Phone,Address,Email,Document,DocumentTypeID")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DocumentTypeID = new SelectList(db.DocumentTypes, "DocumentTypeID", "Description", customer.DocumentTypeID);
     return(View(customer));
 }
Example #17
0
 public ActionResult Edit([Bind(Include = "EmployeeId,FirstName,LastName,DateOfBirth,Address,Phone,Email,StartTime,Salary,BonusPercent,DocumentTypeId")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "DocumentTypeId", "Description", employee.DocumentTypeId);
     return(View(employee));
 }
Example #18
0
 public ActionResult Edit([Bind(Include = "OrderDetailID,OrderID,ProductID,Description,Price,Quantity")] OrderDetail orderDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "OrderID", orderDetail.OrderID);
     ViewBag.ProductID = new SelectList(db.Products, "ProductID", "Description", orderDetail.ProductID);
     return(View(orderDetail));
 }
 public ActionResult Edit([Bind(Include = "ProductInventoryID,ProductID,Description,Stock,Price,SupplierID,LastBuy")] ProductInventory productInventory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productInventory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductID  = new SelectList(db.Products, "ProductID", "Description", productInventory.ProductID);
     ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "Name", productInventory.SupplierID);
     return(View(productInventory));
 }
Example #20
0
 public ActionResult Edit(Flavor flavor, int TreatId)
 {
     if (TreatId != 0)
     {
         _db.TreatFlavor.Add(new TreatFlavor()
         {
             TreatId = TreatId, FlavorId = flavor.FlavorId
         });
     }
     _db.Entry(flavor).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Example #21
0
 public ActionResult Edit([Bind(Include = "ID,Name,JoinDate,location")] Author author)
 {
     if (!author.ID.Equals(User.Identity.GetUserId()))
     {
         return(View("~/Views/Shared/NotOwner.cshtml"));
     }
     if (ModelState.IsValid)
     {
         db.Entry(author).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(author));
 }
Example #22
0
        public async Task <object> AddOrUpdateCompanyPrice(CompanyPriceModel data)
        {
            try
            {
                var foundCompany = await _marketContext.MarketPrices.FirstOrDefaultAsync(x => x.Company.Id == data.CompanyId && x.Market.Id == data.MarketId);

                if (foundCompany != null)
                {
                    foundCompany.Price       = data.Price;
                    foundCompany.DateUpdated = DateTime.Now;

                    _marketContext.Attach(foundCompany);
                    _marketContext.Entry(foundCompany).Property(p => p.Price).IsModified       = true;
                    _marketContext.Entry(foundCompany).Property(p => p.DateUpdated).IsModified = true;

                    await _marketContext.SaveChangesAsync();
                }
                else
                {
                    await _marketContext.MarketPrices.AddAsync(new MarketPrice
                    {
                        CompanyId   = data.CompanyId,
                        MarketId    = data.MarketId,
                        Price       = data.Price,
                        DateUpdated = DateTime.Now
                    });

                    await _marketContext.SaveChangesAsync();
                }

                return(new { Status = true });
            }
            catch (Exception ex)
            {
                return(new { Status = false, Message = $"error message - {ex.Message}" });
            }
        }
Example #23
0
        public ActionResult EditProfile([Bind(Include = "ID, FirstName, LastName, Email, ContactInfo, Password, RePassword, Login")] User user)
        {
            if (!SessionContainer.UserID.ToString().Equals(user.ID.ToString()))
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Profile"));
            }
            return(View(user));
        }
Example #24
0
 public ActionResult Edit([Bind(Include = "AuthorID,CommentID,MarketID,CommentDate,Content")] Comment comment)
 {
     if (!User.Identity.GetUserId().Equals(comment.AuthorID))
     {
         return(View("~/Views/Shared/NotOwner.cshtml"));
     }
     if (ModelState.IsValid)
     {
         db.Entry(comment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", "Market", new { id = comment.MarketID }));
     }
     ViewBag.AuthorID = new SelectList(db.Authors, "AuthorID", "Name", comment.AuthorID);
     ViewBag.MarketID = new SelectList(db.Markets, "ID", "Title", comment.MarketID);
     return(View(comment));
 }
Example #25
0
 public JsonResult AddCart(int itemid)
 {
     //1加商品2加商品数量3超出库存0失败4缺用户
     try
     {
         if (string.IsNullOrEmpty(User.Identity.Name))
         {
             return(Json(4));
         }
         int id = Convert.ToInt16(User.Identity.Name);
         List <Models.Cart> lst = db.Carts.Where(m => m.ItemID == itemid && m.UserID == id && m.IsBought == false).ToList();
         if (lst.Count > 0)
         {
             lst[0].Count++;
             if (lst[0].Count > lst[0].Item.Stock)
             {
                 return(Json(3));
             }
             db.Entry(lst[0]).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(2));
         }
         else
         {
             Models.Cart cart = new Models.Cart();
             cart.UserID     = id;
             cart.ItemID     = itemid;
             cart.CreateTime = System.DateTime.Now;
             cart.Count      = 1;
             cart.IsBought   = false;
             db.Carts.Add(cart);
             db.SaveChanges();
             return(Json(1));
         }
     }
     catch
     {
         return(Json(0));
     }
 }
Example #26
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Description,MainImage,IsDiscount,IsMane,CategoryId,Price,BrandId,ProviderId")] Product product, IFormFile uploadedFile)
        {
            if (id != product.Id)
            {
                return(NotFound());
            }
            //изменение изображения
            _context.Entry(product).State = EntityState.Modified;
            if (uploadedFile != null)
            {
                string path = "/files/" + uploadedFile.FileName;
                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await uploadedFile.CopyToAsync(fileStream);
                }
                product.MainImage = path;
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Example #27
0
        public ActionResult Create(T product)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    throw new Exception(ModelState.ModelStateToString());
                }

                using (var db = new MarketContext())
                {
                    var models = db.Set <T>();

                    if (product.Id == 0)
                    {
                        models.Add(product);
                    }
                    else
                    {
                        var exist = models.Find(product.Id);
                        if (exist == null)
                        {
                            throw new Exception("محصول مورد نظر با کد داده شده یافت نشد");
                        }

                        db.Entry(exist).CurrentValues.SetValues(product);
                    }

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);

                return(PartialView("Error", e));
            }
        }
Example #28
0
 public ActionResult Edit(Treat treat)
 {
     _db.Entry(treat).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Example #29
0
 public void Update(Product product)
 {
     db.Entry(product).State = EntityState.Modified;
 }
Example #30
0
 public void Update(Model model)//Но это не точно
 {
     db.Entry(model).State = EntityState.Modified;
 }