Example #1
0
        public ActionResult Raise(string price, int id)
        {
            using (var db = new BaseDataContext())
            {
                int newPrice = int.Parse(price);
                Lot lot      = db.Lots.FirstOrDefault(b => b.Id == id);
                if (lot == null)
                {
                    return(HttpNotFound());
                }
                if (lot.Price < newPrice)
                {
                    Perchase _perchase = db.Perchases.FirstOrDefault(b => b.LotId == lot.Id);
                    if (_perchase != null)
                    {
                        _perchase.UserId          = int.Parse(Request.Cookies["UserId"].Value);
                        db.Entry(_perchase).State = EntityState.Modified;
                    }
                    else
                    {
                        _perchase        = new Perchase();
                        _perchase.LotId  = lot.Id;
                        _perchase.UserId = int.Parse(Request.Cookies["UserId"].Value);
                        db.Perchases.Add(_perchase);
                    }
                    db.SaveChanges();

                    lot.Price           = int.Parse(price);
                    db.Entry(lot).State = EntityState.Modified;
                    try
                    {
                        db.SaveChanges();
                        return(RedirectToRoute(new { controller = "List", action = "ViewList" }));
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                        {
                            Response.Write("Object: " + validationError.Entry.Entity.ToString());

                            foreach (DbValidationError err in validationError.ValidationErrors)
                            {
                                Response.Write("                                        ");
                                Response.Write(err.ErrorMessage + "");
                            }
                        }
                    };
                }
                Response.Write("Цена слишком мала!");
                return(View());
            }
            //return RedirectToRoute(new { controller = "List", action = "ViewList" });
        }
Example #2
0
        public ActionResult EditLot(Lot _lot)
        {
            using (var db = new BaseDataContext())
            {
                db.Entry(_lot).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();

                    return(RedirectToRoute(new { controller = "List", action = "ViewList" }));
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors)
                    {
                        Response.Write("Object: " + validationError.Entry.Entity.ToString());

                        foreach (DbValidationError err in validationError.ValidationErrors)
                        {
                            Response.Write("                                        ");
                            Response.Write(err.ErrorMessage + "");
                        }
                    }
                };
                return(View());
            }
        }
Example #3
0
 public ActionResult EditLot(Lot _lot)
 {
     using (var db = new BaseDataContext())
     {
         db.Entry(_lot).State = EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToRoute(new { controller = "List", action = "ViewList" }));
 }