예제 #1
0
        public RedirectToRouteResult Add(int productId, string returnUrl, int quantity = 1)
        {
            //var cart = new Cart(this.ControllerContext.HttpContext.User.Identity.Name, repository);
            //Product product = repository.Products.SingleOrDefault(x => x.ProductID == productId);
            //if (product != null) cart.AddProduct(product, 1);
            //return RedirectToAction("Index", new {returnUrl});
            CartItem cart =
                repository.CartItems.SingleOrDefault(
                    x => x.Customer.EmailAddress == this.ControllerContext.HttpContext.User.Identity.Name &&
                    x.ProductId == productId);

            if (cart != null)
            {
                cart.Quantity += quantity;
                repository.Save(cart);
            }
            else
            {
                var customer = repository.Customers.SingleOrDefault(
                    x => x.EmailAddress == this.ControllerContext.HttpContext.User.Identity.Name);
                if (customer != null)
                {
                    cart = new CartItem
                    {
                        ProductId  = productId,
                        CustomerId = customer.CustomerID,
                        Quantity   = quantity
                    };
                    repository.Save(cart);
                }
            }

            return(RedirectToAction("Index", new { returnUrl }));
        }
        public void Add(List <OrderProduct> products)
        {
            CurrentUser = UserManager.FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            foreach (OrderProduct product in products)
            {
                StoredProduct storedProduct = _storedProductRepository.GetEntities()
                                              .Where(p => p.UserId == this.CurrentUser.Id && p.ProductId == product.ProductId)
                                              .FirstOrDefault();
                try
                {
                    storedProduct.Quantity += product.Quantity;
                    _storedProductRepository.Update(storedProduct);
                    _storedProductRepository.Save();
                }
                catch (NullReferenceException e)
                {
                    storedProduct = new StoredProduct()
                    {
                        UserId    = CurrentUser.Id,
                        ProductId = product.ProductId,
                        Quantity  = product.Quantity
                    };
                    _storedProductRepository.Insert(storedProduct);
                    _storedProductRepository.Save();
                }
            }
        }
예제 #3
0
        public void Add(Product product)
        {
            CurrentUser = UserManager.FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
            OrderProduct orderProduct = _orderProductRepository.GetEntities()
                                        .Where(p => p.UserId == this.CurrentUser.Id && p.ProductId == product.ProductId)
                                        .FirstOrDefault();

            try
            {
                orderProduct.Quantity += 1;
                _orderProductRepository.Update(orderProduct);
                _orderProductRepository.Save();
            }
            catch (NullReferenceException e)
            {
                orderProduct = new OrderProduct()
                {
                    UserId    = CurrentUser.Id,
                    ProductId = product.ProductId,
                    Quantity  = 1
                };
                _orderProductRepository.Insert(orderProduct);
                _orderProductRepository.Save();
            }
        }
예제 #4
0
        public ActionResult EditCustomer(CustomerViewModel model)
        {
            var user = repository.Customers.SingleOrDefault(x => x.CustomerID == model.Customer.CustomerID &&
                                                            x.rowguid == model.Customer.rowguid);

            if (user == null)
            {
                // TODO
                // log(User doesn't exist, Existing user try to get access to other accounts)

                FormsAuthentication.SignOut();
                return(Redirect(Url.Action("List", "Product")));
            }
            if (!StringUtils.IsValidPassword(model.OldPassword, user.PasswordSalt, user.PasswordHash))
            {
                ModelState.AddModelError("OldPassword", "Not valid.");
                model.Customer.EmailAddress = user.EmailAddress;
                model.NewPassword           = null;
                model.OldPassword           = null;
                model.RetypeNewPassword     = null;
                return(View(model));
            }
            model.Customer.EmailAddress = user.EmailAddress;
            model.Customer.PasswordHash = user.PasswordHash;
            model.Customer.PasswordSalt = user.PasswordSalt;
            if (model.NewPassword != null)
            {
                if (model.NewPassword.Length > 0)
                {
                    var newpass = StringUtils.getSaltHash(model.NewPassword);
                    model.Customer.PasswordHash = newpass.SingleOrDefault(x => x.Key == "hash").Value;
                    model.Customer.PasswordSalt = newpass.SingleOrDefault(x => x.Key == "salt").Value;
                }
            }
            ModelState.Remove("Customer.EmailAddress");
            ModelState.Remove("Customer.PasswordHash");
            ModelState.Remove("Customer.PasswordSalt");
            model.Customer.NameStyle    = user.NameStyle;
            model.Customer.ModifiedDate = user.ModifiedDate;
            if (ModelState.IsValid)
            {
                try
                {
                    repository.Save(model.Customer);
                    TempData["customer_message"] = "Customer information has been saved";
                    return(RedirectToAction("EditCustomer"));
                }
                catch (Exception ex)
                {
                    TempData["customer_message"] = "Error updating customer information";
                }
            }
            model.NewPassword       = null;
            model.OldPassword       = null;
            model.RetypeNewPassword = null;
            return(View(model));
        }
예제 #5
0
 public ActionResult EditProduct(Product product, HttpPostedFileBase image)
 {
     if (ModelState.IsValid)
     {
         if (image != null)
         {
             product.ThumbnailPhotoFileName = image.FileName;
             product.ThumbNailPhoto         = new byte[image.ContentLength];
             image.InputStream.Read(product.ThumbNailPhoto, 0, image.ContentLength);
         }
         repository.Save(product);
         TempData["admin_message"] = string.Format("{0} has been saved", product.Name);
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
        public ActionResult Create(/*[Bind(Include = "ProductId,Name,UnitPrice,Category,Description")]*/ ProductViewModel productViewModel)
        {
            if (!ModelState.IsValid)
            {
                productViewModel.Categories = _categoryRepository.GetEntities().ToList();
                return(View(productViewModel));
            }
            productViewModel.Product.Category = _categoryRepository.GetEntities().Where(c => c.CategoryId == productViewModel.CategoryId).FirstOrDefault();
            Product product = new Product()
            {
                CategoryId  = productViewModel.Product.Category.CategoryId,
                Name        = productViewModel.Product.Name,
                UnitPrice   = productViewModel.Product.UnitPrice,
                Description = productViewModel.Product.Description
            };

            _productRepository.Insert(product);
            _productRepository.Save();

            return(RedirectToAction("Index"));
        }
예제 #7
0
        public void AddProduct(Product product, int quantity)
        {
            CartItem cartItem = repository.CartItems.FirstOrDefault(x => x.CustomerId == customerId && x.ProductId == product.ProductID);// cartItem = _cart.FirstOrDefault(x => x.Product.ProductID == product.ProductID);

            if (cartItem != null)
            {
                cartItem.Quantity += quantity;
            }
            else
            {
                cartItem = new CartItem {
                    Quantity = quantity, CustomerId = customerId, ProductId = product.ProductID
                };
            }
            repository.Save(cartItem);
        }
예제 #8
0
        public async Task UpdateProduction(Production updatedItem)
        {
            var production = _SalesProducts.Select(d => d.Production).FirstOrDefault(d => d.Id == updatedItem.Id);

            if (production == null)
            {
                return;
            }

            production.Name         = updatedItem.Name;
            production.Weight       = updatedItem.Weight;
            production.TransferRate = updatedItem.TransferRate;
            production.MarginRate   = updatedItem.MarginRate;

            var productions = _SalesProducts.Select(d => d.Production).Distinct().ToList();

            await _ProductionRepo.Save(productions);
        }
예제 #9
0
        private bool AddUser(RegisterViewModel user)
        {
            Customer newuser = new Customer();

            newuser.FirstName    = user.FirstName;
            newuser.LastName     = user.LastName;
            newuser.EmailAddress = user.UserName;
            var pass = StringUtils.getSaltHash(user.Password);

            newuser.PasswordHash = pass.SingleOrDefault(x => x.Key == "hash").Value;
            newuser.PasswordSalt = pass.SingleOrDefault(x => x.Key == "salt").Value;
            newuser.NameStyle    = false;
            try
            {
                repository.Save(newuser);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public IActionResult AddProduction([FromBody] Production productionToAdd)
        {
            if (productionToAdd == null)
            {
                return(BadRequest());
            }

            var production = productionToAdd;//_mapper.Map<Production>(productionToAdd);

            if (production.ProductionId == Guid.Empty)
            {
                return(new UnprocessableEntityResult(ModelState));
            }

            _productionRepository.Add(production);
            _productionRepository.Save();

            var productionToGet = _mapper.Map <Production>(production);

            return(CreatedAtRoute("GetProduction",
                                  new { id = productionToGet.ProductionId },
                                  productionToGet));
        }
예제 #11
0
        // GET: Cart/Return
        public ActionResult Return(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            _orderProductRepository = new OrderProductRepository(new Data.DAL.Context.ApplicationDbContext());
            OrderProduct orderProduct = _orderProductRepository.GetDetails(id);

            orderProduct.Quantity -= 1;

            if (orderProduct.Quantity == 0)
            {
                _orderProductRepository.Delete(id.GetValueOrDefault());
            }
            else
            {
                _orderProductRepository.Update(orderProduct);
            }
            _orderProductRepository.Save();

            return(RedirectToAction("Index"));
        }