Ejemplo n.º 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" });
        }
Ejemplo n.º 2
0
 public void Registration(User us)
 {
     using (var db = new BaseDataContext())
     {
         var Log = db.Users.FirstOrDefault(b => b.Login == us.Login);
         if (Log == null)
         {
             ViewBag.UserAuth = true;
             us.Role          = 0;
             db.Users.Add(us);
             db.SaveChanges();
             Response.Cookies["UserId"].Value     = Convert.ToString(us.Id);
             Response.Cookies["UserId"].Expires   = DateTime.Now.AddDays(1);
             Response.Cookies["UserName"].Value   = Convert.ToString(us.Name);
             Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(1);
             Response.Cookies["UserRole"].Value   = Convert.ToString(us.Role);
             Response.Cookies["UserRole"].Expires = DateTime.Now.AddDays(1);
             Response.Redirect("/");
         }
         else
         {
             ModelState.AddModelError("", "Логин уже занят");
             //return View();
         }
     }
 }
Ejemplo n.º 3
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());
            }
        }
Ejemplo n.º 4
0
        /*public User GetUser(int id)
         * {
         *  using (var db = new BaseDataContext())
         *  {
         *      return db.Users.FirstOrDefault(b => b.Id == id);
         *  }
         * }
         *
         * public Lot GetLot(int id)
         * {
         *  using (var db = new BaseDataContext())
         *  {
         *      return db.Lots.FirstOrDefault(b => b.Id == id);
         *  }
         * }*/

        public void DeletePerchase(int id)
        {
            using (var db = new BaseDataContext())
            {
                var p = db.Perchases.First(b => b.Id == id);
                db.Perchases.Remove(p);
                db.SaveChanges();
            }
        }
Ejemplo n.º 5
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" }));
 }
Ejemplo n.º 6
0
        public ServicingCodeBuilder SaveToDb()
        {
            using (var context = new BaseDataContext())
            {
                context.ServicingCodes.Add(entity);
                context.SaveChanges();
            }

            return(this);
        }
Ejemplo n.º 7
0
 public void DeleteConfirmed1(int id)
 {
     using (var db = new BaseDataContext())
     {
         User l = db.Users.Find(id);
         if (l != null)
         {
             db.Users.Remove(l);
             db.SaveChanges();
         }
     }
     Response.Redirect("~/Admin/ViewListUsers");
     //return RedirectToRoute(new { controller = "Admin", action = "ViewList" });
 }
Ejemplo n.º 8
0
        public ActionResult DeleteConfirmed(int id)
        {
            using (var db = new BaseDataContext())
            {
                Lot l = db.Lots.Find(id);
                if (l != null)
                {
                    db.Lots.Remove(l);
                    db.SaveChanges();
                }
            }

            return(RedirectToRoute(new { controller = "List", action = "ViewList" }));
        }
Ejemplo n.º 9
0
 public ActionResult AddLot(Lot _lot)
 {
     using (var db = new BaseDataContext())
     {
         if (_lot.ExpirationDateTime == null)
         {
             DateTime dt = DateTime.Today;
             dt.AddDays(5);
             _lot.ExpirationDateTime = dt;
         }
         db.Lots.Add(_lot);
         db.SaveChanges();
     }
     return(RedirectToRoute(new { controller = "List", action = "ViewList" }));//!!!!!!!!!!!!!!!!
 }