public ActionResult <IEnumerable <ProductModel> > GetProductByIdCategory(int?categoryId) { using (var _context = new COMMERCEContext()) { return((categoryId == 0 || categoryId == null) ? _context.Products.Select(_ => new ProductModel { ProductId = _.ProductId, Description = _.Description, ModelName = _.ModelName, ProductImage = _.ProductImage, ModelNumber = _.ModelNumber, UnitCost = _.UnitCost, CategoryId = _.CategoryId } ).ToList() : _context.Products.Where(_ => _.CategoryId == categoryId) .Select(_ => new ProductModel { ProductId = _.ProductId, Description = _.Description, ModelName = _.ModelName, ProductImage = _.ProductImage, ModelNumber = _.ModelNumber, UnitCost = _.UnitCost, CategoryId = _.CategoryId } ).ToList()); } }
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)); }
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)); }
public ActionResult <IEnumerable <CategoryModel> > Get() { using (var _ctx = new COMMERCEContext()) { return(_ctx.Categories.Select(_ => new CategoryModel { CategoryId = _.CategoryId, CategoryName = _.CategoryName }).ToList()); } }
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)); } }
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("")); }
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("")); }
public ActionResult <List <ProfileModel> > GetAllUsers() { using (var ctx = new COMMERCEContext()) { var querCustumer = (from c in ctx.CustumerUser join r in ctx.CustomerRole on c.CustumerRoleId equals r.CustumerRoleId select new ProfileModel { Id = c.CustumerId, FirstName = c.CustumerName, LastName = c.CustumerLastName, UserName = c.Customerlogin, Role = r.CustumerRole }).ToList(); return(Ok(querCustumer)); } }
public ActionResult <ProductModel> GetById(int?productId) { using (var _context = new COMMERCEContext()) { return(_context.Products.Where(_ => _.ProductId == productId) .Select(_ => new ProductModel { ProductId = _.ProductId, Description = _.Description, ModelName = _.ModelName, ProductImage = _.ProductImage, ModelNumber = _.ModelNumber, UnitCost = _.UnitCost, CategoryId = _.CategoryId } ).FirstOrDefault()); } }
public ActionResult <IEnumerable <ProductModel> > Get() { using (var _ctx = new COMMERCEContext()) { var products = _ctx.Products.Select( p => new ProductModel { CategoryId = p.CategoryId, ProductId = p.ProductId, Description = p.Description, ModelName = p.ModelName, ModelNumber = p.ModelNumber, ProductImage = p.ProductImage, UnitCost = p.UnitCost }).ToList(); return(products); } }
public ActionResult GetById(int id) { using (var ctx = new COMMERCEContext()) { var Custumer = (from c in ctx.CustumerUser join r in ctx.CustomerRole on c.CustumerRoleId equals r.CustumerRoleId where c.CustumerId == id select new ProfileModel { Id = c.CustumerId, FirstName = c.CustumerName, LastName = c.CustumerLastName, Role = r.CustumerRole }).FirstOrDefault(); return(Ok(Custumer)); } }
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("")); }
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)); } } }
public ActionResult <ProfileModel> LoginCustumer([FromBody] LoginModel model) { using (var ctx = new COMMERCEContext()) { var foundCustumer = (from c in ctx.CustumerUser join r in ctx.CustomerRole on c.CustumerRoleId equals r.CustumerRoleId where c.Customerlogin == model.Login && c.Custumerpassword == model.PassWord select new ProfileModel { Id = c.CustumerId, FirstName = c.CustumerName, LastName = c.CustumerLastName, UserName = c.Customerlogin, Role = r.CustumerRole }).FirstOrDefault(); if (foundCustumer != null) { return(Ok(foundCustumer)); } return(Ok()); } }