Пример #1
0
        public ActionResult Create(Guia guia)
        {
            if (ModelState.IsValid)
            {
                db.Guia.Add(guia);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(guia));
        }
Пример #2
0
        public ActionResult Create(Contato contato)
        {
            if (ModelState.IsValid)
            {
                db.Contato.Add(contato);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contato));
        }
Пример #3
0
        public ActionResult Create(Genero genero)
        {
            if (ModelState.IsValid)
            {
                db.Genero.Add(genero);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genero));
        }
Пример #4
0
        public ActionResult Complete(int id)
        {
            // Validate customer owns this order
            bool isValid = db.Reserva.Any(
                o => o.OrdemId == id &&
                o.Username == User.Identity.Name);

            if (isValid)
            {
                //Limpa carrinho
                //var cartItem = db.Carrinho.Include(cart => cart.CarrinhoId == User.Identity.Name).ToList();

                var cartItem  = db.Carrinho.Where(cart => cart.CarrinhoId == User.Identity.Name).ToList();
                int itemCount = 0;

                if (cartItem != null)
                {
                    if (cartItem.Count > 1)
                    {
                        foreach (var aux in cartItem)
                        {
                            aux.Count--;
                            itemCount = cartItem.Count;
                            db.Carrinho.Remove(aux);

                            if (cartItem == null)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        db.Carrinho.Remove(cartItem.FirstOrDefault());
                    }

                    // Save changes
                    db.SaveChanges();
                }


                //Renova Session

                Session.Contents.Abandon();
                Session.Contents.RemoveAll();
                Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId"));

                return(View(id));
            }
            else
            {
                return(View("Error"));
            }
        }
        public ActionResult Create(Transportadora transportadora)
        {
            if (ModelState.IsValid)
            {
                db.Transportadora.Add(transportadora);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(transportadora));
        }
Пример #6
0
        public ActionResult Create(Veiculo veiculo)
        {
            if (ModelState.IsValid)
            {
                db.Veiculo.Add(veiculo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TransportadoraId = new SelectList(db.Transportadora, "ID", "Nome", veiculo.TransportadoraId);
            return(View(veiculo));
        }
Пример #7
0
        public ActionResult Create(Excurcao excurcao)
        {
            if (ModelState.IsValid)
            {
                db.Excurcao.Add(excurcao);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.GeneroId   = new SelectList(db.Genero, "ID", "Nome", excurcao.GeneroId);
            ViewBag.GuiaId     = new SelectList(db.Guia, "ID", "Nome", excurcao.GuiaId);
            ViewBag.VeicuiloId = new SelectList(db.Veiculo, "VeiculoId", "MarcaCarro", excurcao.VeicuiloId);
            return(View(excurcao));
        }
Пример #8
0
        public dynamic PlaceOrder(Order _order)
        {
            try
            {
                Customer cus        = _context.Customers.Where(w => w.Email == _order.email).FirstOrDefault();
                int      CustomerID = 0;
                if (cus == null)
                {
                    Customer _objCus = new Customer();
                    _objCus.Name        = _order.name;
                    _objCus.Email       = _order.email;
                    _objCus.Address     = _order.address;
                    _objCus.TelephoneNo = _order.tel;

                    _context.Customers.Add(_objCus);
                    _context.SaveChanges();

                    CustomerID = _objCus.CustomerID;
                }
                else
                {
                    CustomerID = cus.CustomerID;
                }

                CustomerOrder _cusOrder = new CustomerOrder();
                _cusOrder.CustomerID = CustomerID;
                _context.CustomerOrders.Add(_cusOrder);
                _context.SaveChanges();

                foreach (var items in _order.ItemList)
                {
                    ShoppingCart cusOrder = new ShoppingCart();
                    cusOrder.OrderID  = _cusOrder.OrderID;
                    cusOrder.ItemID   = Convert.ToInt32(items._id);
                    cusOrder.Qty      = Convert.ToInt32(items.quantity);
                    cusOrder.Price    = Convert.ToDouble(items.price);
                    cusOrder.ItemNote = items.userNotes;

                    _context.ShoppingCarts.Add(cusOrder);
                    _context.SaveChanges();
                }

                return("Your Order Place Sucessfully. Order ID : " + _cusOrder.OrderID);
            }
            catch (Exception ex)
            {
                return("Error. Error Msg : " + ex.Message);
            }
        }
Пример #9
0
 public bool Update(string id, SYS_GroupLayer model)
 {
     if (model == null)
     {
         throw new ArgumentNullException();
     }
     try
     {
         using (var context = new SystemEntities())
         {
             var baseModel = context.SYS_GroupLayer.FirstOrDefault(f => f.ID.Equals(id));
             if (baseModel == null)
             {
                 throw new NullReferenceException("Không tìm thấy đối tượng trong cơ sở dữ liệu");
             }
             else
             {
                 model.ID = id;
                 context.Entry(baseModel).CurrentValues.SetValues(model);
                 return(context.SaveChanges() > 0);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public DBResult EditAll(List <User> entities)
        {
            if (entities == null)
            {
                return(DBResult.WrongParameter);
            }

            using (var db = new SystemEntities())
            {
                foreach (var entity in entities)
                {
                    if (EntityHelper.HasNullProperty(entity, new string[] { "Password" }))
                    {
                        return(DBResult.WrongParameter);
                    }

                    var user = db.User.FirstOrDefault(u => u.ID == entity.ID);
                    if (user == null)
                    {
                        return(DBResult.NotFound);
                    }

                    var existResult = CheckExists(db.User, new string[] { "ShortID", "UserName" }, entity, true);
                    if (existResult != DBResult.Succeed)
                    {
                        return(existResult);
                    }

                    EntityHelper.CopyEntity(entity, user, new string[] { "Password" });
                }

                db.SaveChanges();
                return(DBResult.Succeed);
            }
        }
Пример #11
0
 public SYS_Layer_Account Create(SYS_Layer_Account model)
 {
     try
     {
         using (var context = new SystemEntities())
         {
             if (model != null)
             {
                 var addModel = context.SYS_Layer_Account.Add(model);
                 var result   = context.SaveChanges();
                 if (result > 0)
                 {
                     return(addModel);
                 }
                 else
                 {
                     return(null);
                 }
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #12
0
 public bool Update(int id, SYS_Layer_Account model)
 {
     if (model == null)
     {
         throw new ArgumentNullException();
     }
     try
     {
         using (var context = new SystemEntities())
         {
             var baseModel = context.SYS_Layer_Account.FirstOrDefault(f => f.ID.Equals(id));
             if (baseModel == null)
             {
                 throw new NullReferenceException("Không tìm thấy đối tượng trong cơ sở dữ liệu");
             }
             else
             {
                 model.ID = id;
                 context.Entry(baseModel).CurrentValues.SetValues(model);
                 //context.Entry(model).State = System.Data.Entity.EntityState.Modified;
                 //context.SYS_Layer_Account.Attach(model);
                 return(context.SaveChanges() > 0);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #13
0
        public ActionResult PeopleForm(FormCollection values)
        {
            var order = new Ordem();

            TryUpdateModel(order);

            try
            {
                order.Username  = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                //Save Order
                storeDB.Ordem.Add(order);
                storeDB.SaveChanges();

                //Process the order
                var cart = ShoppingCart.GetCart(this.HttpContext);
                cart.CreateOrder(order);

                return(RedirectToAction("Complete",
                                        new { id = order.OrdemId }));
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
        public DBResult ChangePassword(User entity)
        {
            if (entity == null || entity.ID == 0 || string.IsNullOrEmpty(entity.Password))
            {
                return(DBResult.WrongParameter);
            }

            using (var db = new SystemEntities())
            {
                var user = db.User.FirstOrDefault(u => u.ID == entity.ID);
                if (user == null)
                {
                    return(DBResult.NotFound);
                }

                user.Password = entity.Password;

                db.SaveChanges();
                return(DBResult.Succeed);
            }
        }
Пример #15
0
 public SYS_Version Create(SYS_Version model)
 {
     using (var context = new SystemEntities())
     {
         if (model != null)
         {
             var addModel = context.SYS_Version.Add(model);
             var result   = context.SaveChanges();
             if (result > 0)
             {
                 return(addModel);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(null);
         }
     }
 }
Пример #16
0
 public bool Delete(int id)
 {
     try
     {
         using (var context = new SystemEntities())
         {
             var model = context.SYS_Layer_Account.FirstOrDefault(f => f.ID.Equals(id));
             if (model != null)
             {
                 context.SYS_Layer_Account.Remove(model);
                 return(context.SaveChanges() > 0);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #17
0
 public bool Create(List <SYS_Logger_Layer> models)
 {
     try
     {
         using (var context = new SystemEntities())
         {
             if (models != null && models.Count > 0)
             {
                 var addModel = context.SYS_Logger_Layer.AddRange(models);
                 var result   = context.SaveChanges();
                 return(result > 0);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #18
0
 public void SaveToDb()
 {
     context.SaveChanges();
 }