示例#1
0
        public async Task <IActionResult> Offer(int id)
        {
            Offer offer = await db.Offers.FindAsync(id);

            if (offer == null || (offer.IsVerified != true && !await userManager.IsInRoleAsync(await userManager.GetUserAsync(User), "moderator")))
            {
                return(NotFound());
            }

            db.Entry(offer).Reference(o => o.Price).Load();
            db.Entry(offer).Reference(o => o.Category).Load();
            db.Entry(offer).Reference(o => o.User).Load();
            return(View(offer));
        }
 public ActionResult Edit([Bind(Include = "Id,Make,Model,Size,Material,,Price,Description,CategoryId")] Product product, HttpPostedFileBase upload)
 {
     if (ModelState.IsValid)
     {
         if (upload != null && upload.ContentLength > 0)
         {
             if (product.Files.Any(f => f.FileType == FileType.Avatar))
             {
                 db.Files.Remove(product.Files.First(f => f.FileType == FileType.Avatar));
             }
             var avatar = new File
             {
                 FileName    = System.IO.Path.GetFileName(upload.FileName),
                 FileType    = FileType.Avatar,
                 ContentType = upload.ContentType
             };
             using (var reader = new System.IO.BinaryReader(upload.InputStream))
             {
                 avatar.Content = reader.ReadBytes(upload.ContentLength);
             }
             product.Files = new List <File> {
                 avatar
             };
         }
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Title", product.CategoryId);
     return(View(product));
 }
        public ActionResult Edit(Category category, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                using (var database = new MarketplaceContext())
                {
                    //if (upload != null && upload.ContentLength > 0)
                    //{
                    //    if (category.Files.Any(f => f.FileType == FileType.Avatar))
                    //    {
                    //        database.Files.Remove(category.Files.First(f => f.FileType == FileType.Avatar));
                    //    }
                    //    var avatar = new File
                    //    {
                    //        FileName = System.IO.Path.GetFileName(upload.FileName),
                    //        FileType = FileType.Avatar,
                    //        ContentType = upload.ContentType
                    //    };
                    //    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    //    {
                    //        avatar.Content = reader.ReadBytes(upload.ContentLength);
                    //    }
                    //    category.Files = new List<File> { avatar };
                    //}
                    database.Entry(category).State = EntityState.Modified;
                    database.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            return(View(category));
        }
        public void DeleteCategory(Category category)
        {
            MarketplaceContext context = new MarketplaceContext();

            context.Entry(category).State = System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
        public void DeleteAuction(Auction auction)
        {
            MarketplaceContext context = new MarketplaceContext();

            context.Entry(auction).State = System.Data.Entity.EntityState.Deleted;

            context.SaveChanges();
        }
 public ActionResult Edit([Bind(Include = "Id,ShippingAddress,Fullname,ProductId")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId = new SelectList(db.Products, "Id", "Make", order.ProductId);
     return(View(order));
 }
        public ActionResult Edit(ProductViewModel model, HttpPostedFileBase upload)
        {
            // Check if model state is valid
            if (ModelState.IsValid)
            {
                using (var database = new MarketplaceContext())
                {
                    // Get article from database
                    var product = database.Products
                                  .FirstOrDefault(a => a.Id == model.Id);

                    // Set article properties
                    model.Id          = product.Id;
                    model.Model       = product.Model;
                    model.Make        = product.Make;
                    model.Material    = product.Material;
                    model.Price       = product.Price;
                    model.Description = product.Description;
                    model.Categories  = database.Categories
                                        .OrderBy(c => c.Title)
                                        .ToList();
                    model.Files = product.Files;

                    if (upload != null && upload.ContentLength > 0)
                    {
                        if (product.Files.Any(f => f.FileType == FileType.Avatar))
                        {
                            database.Files.Remove(product.Files.First(f => f.FileType == FileType.Avatar));
                        }
                        var avatar = new File
                        {
                            FileName    = System.IO.Path.GetFileName(upload.FileName),
                            FileType    = FileType.Avatar,
                            ContentType = upload.ContentType
                        };
                        using (var reader = new System.IO.BinaryReader(upload.InputStream))
                        {
                            avatar.Content = reader.ReadBytes(upload.ContentLength);
                        }
                        product.Files = new List <File> {
                            avatar
                        };
                    }

                    // Save article state in database
                    database.Entry(product).State = EntityState.Modified;
                    database.SaveChanges();
                }
            }

            // Redirect to the index page
            return(RedirectToAction("Index"));
        }
        public void UpdateAuction(Auction auction)
        {
            MarketplaceContext context = new MarketplaceContext();

            var existingAuction = context.Auctions.Find(auction.ID);

            context.AuctionPictures.RemoveRange(existingAuction.AuctionPictures);

            context.Entry(existingAuction).CurrentValues.SetValues(auction);

            context.AuctionPictures.AddRange(auction.AuctionPictures);

            context.SaveChanges();
        }
        public ActionResult Edit(string id, EditUserViewModel viewModel)
        {
            //Chek if model is valid
            if (ModelState.IsValid)
            {
                using (var database = new MarketplaceContext())
                {
                    //Get User from database
                    var user = database.Users.FirstOrDefault(u => u.Id == id);

                    //Check for user exists
                    if (user == null)
                    {
                        return(HttpNotFound());
                    }

                    //IF password fiesld is not empty, change password
                    if (!string.IsNullOrEmpty(viewModel.Password))
                    {
                        var hasher       = new PasswordHasher();
                        var passwordHash = hasher.HashPassword(viewModel.Password);
                        user.PasswordHash = passwordHash;
                    }

                    //set user properties
                    user.Email    = viewModel.User.Email;
                    user.UserName = viewModel.User.Email;
                    this.SetUserRoles(viewModel, user, database);

                    //Save changes
                    database.Entry(user).State = EntityState.Modified;
                    database.SaveChanges();

                    return(RedirectToAction("List"));
                }
            }
            return(View(viewModel));
        }
示例#10
0
 public async Task Update(TEntity entity)
 {
     Db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
     await Db.SaveChangesAsync();
 }