コード例 #1
0
        public ActionResult UpdateUser([FromBody] ProfileModel userModel)
        {
            if (userModel != null)
            {
                using (var ctx = new COMMERCEContext())
                {
                    var foundUser = ctx.CustumerUser
                                    .Where(u => u.CustumerId == userModel.Id)
                                    .Select(u => new CustumerUser
                    {
                        CustumerId       = userModel.Id,
                        Customerlogin    = userModel.UserName,
                        CustumerLastName = userModel.LastName,
                        CustumerName     = userModel.FirstName,
                        Custumerpassword = u.Custumerpassword,
                        CustumerRoleId   = (userModel.Role.Equals("admin")) ? 1 : 2
                    })
                                    .FirstOrDefault();

                    if (foundUser != null)
                    {
                        ctx.CustumerUser.Update(foundUser);
                        ctx.SaveChanges();
                        return(Ok(true));
                    }
                }
            }
            return(Ok(false));
        }
コード例 #2
0
        public ActionResult UpdateProfile([FromBody] UpdateProfileModel model)
        {
            if (model != null)
            {
                using (var ctx = new COMMERCEContext())
                {
                    var foundUser = ctx.CustumerUser
                                    .Where(_ => _.CustumerId == model.Id)
                                    .FirstOrDefault();
                    if (foundUser == null)
                    {
                        return(Ok(-1));
                    }

                    foundUser.CustumerId       = model.Id;
                    foundUser.Customerlogin    = model.LoginName;
                    foundUser.CustumerLastName = model.LastName;
                    foundUser.CustumerName     = model.FirstName;
                    foundUser.Custumerpassword = model.Password.Equals(string.Empty) ? foundUser.Custumerpassword : model.Password;


                    ctx.CustumerUser.Update(foundUser);
                    ctx.SaveChanges();
                    return(Ok(1));
                }
            }
            return(Ok(-1));
        }
コード例 #3
0
 public IActionResult PostCategory(CategoryModel model)
 {
     using (var _ctx = new COMMERCEContext())
     {
         var category = new Categories
         {
             CategoryId   = model.CategoryId,
             CategoryName = model.CategoryName
         };
         _ctx.Add(category);
         _ctx.SaveChanges();
         return(Ok(model.CategoryId));
     }
 }
コード例 #4
0
        public IActionResult PostProduct(ShoppingCartModel model)
        {
            using (var _ctx = new COMMERCEContext())
            {
                var existingProduct = _ctx.
                                      ShoppingCart.
                                      Where(s => s.ProductId == model.ProductId && s.CartId == model.CartId)
                                      .FirstOrDefault();

                if (existingProduct != null)
                {
                    var upshoppingCart = new ShoppingCart
                    {
                        DateCreated = System.DateTime.Now,
                        ProductId   = model.ProductId,
                        Quantity    = model.Quantity + 1,
                        CartId      = model.CartId
                    };
                    _ctx.ShoppingCart.Update(upshoppingCart);
                    _ctx.SaveChanges();
                    return(Ok(existingProduct.Quantity));
                }
                else
                {
                    var shoppingCart = new ShoppingCart
                    {
                        DateCreated = System.DateTime.Now,
                        ProductId   = model.ProductId,
                        Quantity    = model.Quantity,
                        CartId      = model.CartId
                    };
                    _ctx.ShoppingCart.Add(shoppingCart);
                    _ctx.SaveChanges();
                    return(Ok(shoppingCart.Quantity));
                }
            }
        }
コード例 #5
0
        public IActionResult DeleteCategory(int categoryID)
        {
            if (categoryID > 0)
            {
                using (var _ctx = new COMMERCEContext())
                {
                    var foundCategory = _ctx.Categories.Where(c => c.CategoryId == categoryID).FirstOrDefault();
                    if (foundCategory != null)
                    {
                        _ctx.Remove(foundCategory);
                        _ctx.SaveChanges();
                    }
                }
            }

            return(Ok(""));
        }
コード例 #6
0
        public IActionResult DeleteProduct(int prodcutId)
        {
            if (prodcutId > 0)
            {
                using (var _ctx = new COMMERCEContext())
                {
                    var product = _ctx.Products.Where(p => p.ProductId == prodcutId).FirstOrDefault();

                    if (product != null)
                    {
                        _ctx.Products.Remove(product);
                        _ctx.SaveChanges();
                    }
                }
            }
            return(Ok(""));
        }
コード例 #7
0
        public IActionResult PostProduct(IList <IFormFile> files, [ModelBinder(BinderType = typeof(JsonModelBinder))] ProductModel Model)
        {
            string fileName = string.Empty;

            if (files?.Any() == true)
            {
                string folderName = @"D://Projects//ng//E-Com//src//resource";
                var    pathToSave = Path.Combine(Directory.GetCurrentDirectory(), folderName);

                for (int i = 0; i < files.Count(); i++)
                {
                    fileName = ContentDispositionHeaderValue.Parse(files[i].ContentDisposition).FileName.Trim('"');
                    var fullPath = Path.Combine(pathToSave, fileName);
                    var dbPath   = Path.Combine(folderName, fileName);

                    using (var stream = new FileStream(fullPath, FileMode.Create))
                    {
                        files[i].CopyTo(stream);
                    }
                }
            }
            var pr = new Products();

            if (Model != null)
            {
                pr.CategoryId   = Model.CategoryId;
                pr.ModelName    = Model.ModelName;
                pr.ModelNumber  = Model.ModelNumber;
                pr.ProductImage = fileName;
                pr.Description  = Model.Description;
                using (var _context = new COMMERCEContext())
                {
                    _context.Products.Add(pr);
                    _context.SaveChanges();
                }


                return(Ok(pr.ProductId));
            }
            return(Ok(""));
        }