public ActionResult Create(ProductModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { var product = new Product() { Active = model.Active, CategoryID = model.CategoryID, CreatedBy = User.Identity.Name, UpdatedBy = User.Identity.Name, Description = model.Description, Name = model.Name, ProductID = Guid.NewGuid(), SubCategoryID = model.SubCategoryID, BrandID = model.BrandID, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }; _dbContext.Products.Add(product); _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "Product created successfully with name=" + product.ProductID, "Create", "ProductController", User.Identity.Name); return(RedirectToAction("AddImageFeatureDetails", "Product", new { id = product.ProductID })); } } CreateViewBagForProduct(); return(View()); }
public ActionResult AddStockPrice(ProductStockPriceModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { var productSizeMapping = new ProductSizeMapping() { ProductID = model.ProductID, SizeID = model.SizeID, UnitID = model.UnitID, Stock = model.Stock }; _dbContext.ProductSizeMappings.Add(productSizeMapping); var productprice = new ProductPrice() { UnitID = model.UnitID, CurrencyID = model.CurrencyID, ProductID = model.ProductID, SizeID = model.SizeID, Price = Convert.ToDecimal(model.Price) }; _dbContext.ProductPrices.Add(productprice); var productShipping = new ProductShipping() { UnitID = model.UnitID, ProductID = model.ProductID, SizeID = model.SizeID, Cost = Convert.ToDecimal(model.ShippingCost) }; _dbContext.ProductShippings.Add(productShipping); _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "Product Stock and price added successfully with ID=" + model.Name, "AddStockPrice", "ProductController", User.Identity.Name); return(RedirectToAction("Index", "Product")); } } CreateViewBagForStockPrice(); return(View()); }
public UserInformation LoginUser(UserModel model) { var userInfo = new UserInformation(); if (ValidateUser(model)) { using (_context = new karrykartEntities()) { var user = _context.Users.Where(x => x.EmailAddress == model.user).FirstOrDefault(); if (user.UserLogins.Count == 0) { var userLogin = new UserLogin() { LoginTime = DateTime.Now, Token = Guid.NewGuid(), TokenExpiry = DateTime.Now.AddDays(15), UserID = user.UserID }; _context.UserLogins.Add(userLogin); _context.SaveChanges(); userInfo.ExpiryDateTime = userLogin.TokenExpiry.Value; userInfo.Token = userLogin.Token.Value; userInfo.UserID = userLogin.UserID.Value; userInfo.Name = model.user;//(user.UserDetails != null) ? user.UserDetails.FirstOrDefault().FirstName : model.user; } } } else { userInfo.Error = "invalid_user"; } return(userInfo); }
public ActionResult SizeTypeDetails() { using (_dbContext = new karrykartEntities()) { return(View(_dbContext.SizeTypes.ToList())); } return(View()); }
public CartModel UpdateCart(CartModel cartModel) { _context = new karrykartEntities(); var cart = _context.Carts.Find(cartModel.CartID); if (cart != null) { var product = cart.CartProducts.Where(x => x.ProductID == cartModel.ProductID).FirstOrDefault(); if (product != null) { if (cartModel.IsQuantityUpdate) { product.Quantity = cartModel.Quantity; } else { product.Quantity = product.Quantity + 1; } _context.Entry(product).State = System.Data.Entity.EntityState.Modified; } else { _context.CartProducts.Add(new CartProduct() { CartID = cart.ID, ProductID = cartModel.ProductID, Quantity = cartModel.Quantity }); } _context.SaveChanges(); cartModel.ProductCount = cart.CartProducts.Sum(x => x.Quantity).Value; } return(cartModel); }
public CartModel DeleteCart(Guid CartID, Guid ProductID) { _context = new karrykartEntities(); var cart = _context.Carts.Find(CartID); if (cart != null) { var products = cart.CartProducts.Where(x => x.ProductID == ProductID).FirstOrDefault(); if (products != null) { _context.Entry(products).State = System.Data.Entity.EntityState.Deleted; } _context.SaveChanges(); if (cart.CartProducts.Count == 0) { _context.Entry(cart).State = System.Data.Entity.EntityState.Deleted; _context.SaveChanges(); return(null); } return(new CartModel() { CartID = CartID }); } return(null); }
public CartDetailsModel GetCart(Guid CartID) { using (_context = new karrykartEntities()){ var cartModel = new CartDetailsModel(); var cart = _context.Carts.Find(CartID); var productHelper = new ProductHelper(); if (cart != null) { cartModel.CartID = cart.ID; cartModel.CartCount = cart.CartProducts.Sum(x => x.Quantity).Value; foreach (var prod in cart.CartProducts) { var product = productHelper.GetProductDetail(prod.ProductID.Value); if (product != null) { cartModel.Products.Add(new CartProductModel(product, prod.Quantity.Value)); cartModel.CartTotal += Convert.ToDouble(product.Prices.FirstOrDefault().Price *prod.Quantity.Value); } } cartModel.TaxPercentage = 5; cartModel.SubTotal = ((double)(cartModel.TaxPercentage) / 100) * cartModel.CartTotal; cartModel.GrandTotal = cartModel.CartTotal + cartModel.SubTotal; cartModel.User = cart.CartUserID.Value; cartModel.Username = (_context.Users.Any(x => x.UserID == cart.CartUserID))?"Registered User":"******"; return(cartModel); } } return(null); }
public CartModel CreateCart(CartModel cartModel) { _context = new karrykartEntities(); Cart userCart = new Cart() { ID = Guid.NewGuid(), CartUserID = cartModel.User == Guid.Empty?Guid.NewGuid():cartModel.User }; _context.Carts.Add(userCart); _context.SaveChanges(); _context.CartProducts.Add(new CartProduct() { CartID = userCart.ID, ProductID = cartModel.ProductID, Quantity = cartModel.Quantity }); _context.SaveChanges(); cartModel.CartID = userCart.ID; cartModel.ProductCount = userCart.CartProducts.Sum(x => x.Quantity).Value; cartModel.User = userCart.CartUserID.Value; cartModel.UserName = string.IsNullOrEmpty(cartModel.UserName)?"Guest":cartModel.UserName; _context = null; return(cartModel); }
public List <ProductModel> GetAllProducts(bool ActiveOnly = true) { _context = new karrykartEntities(); List <Guid> productIDs = null; List <ProductModel> lstProducts = null; if (ActiveOnly) { productIDs = _context.Products.Where(x => x.Active == ActiveOnly).Select(x => x.ProductID).ToList(); } else { productIDs = _context.Products.Select(x => x.ProductID).ToList(); } if (productIDs.Count > 0) { lstProducts = new List <ProductModel>(); foreach (var id in productIDs) { lstProducts.Add(GetProductDetail(id)); } } productIDs = null; return(lstProducts); }
public void WriteLog(string messageType, string message, string methodName, string fileName, string userName) { var log = new Log(){ EventTimeStamp = DateTime.UtcNow, FileName = fileName, IpAddress = GetIPAddress(), Message = message, MessageType = messageType, MethodName = methodName, UserName = userName, Browser = HttpContext.Current.Request.UserAgent}; try { _dbContext = new karrykartEntities(); _dbContext.Logs.Add(log); _dbContext.SaveChanges(); } catch (Exception ex) { } finally { _dbContext = null; } }
public ActionResult EditBasicProductDetails(ProductDetailsModel model) { if (model.ProductID != Guid.Empty) { _dbContext = new karrykartEntities(); var product = _dbContext.Products.Find(model.ProductID); if (product != null) { product.Active = model.Active; product.BrandID = model.BrandID; product.CategoryID = model.CategoryID; product.SubCategoryID = model.SubCategoryID; product.Description = model.Description; product.Name = model.Name; product.UpdatedBy = User.Identity.Name; product.UpdatedOn = DateTime.Now; _dbContext.Entry(product).State = EntityState.Modified; _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "Basic product details updated successfully with Name=" + model.Name, "EditBasicProductDetails", "ProductController", User.Identity.Name); return(Json(new { messagetype = ApplicationMessages.Product.SUCCESS, message = "Basic product details updated successfully." })); } } return(View()); }
public ActionResult Edit(int id=-1) { if (id != -1) { using (_dbContext = new karrykartEntities()) { var objSlide = _dbContext.Sliders.Find(id); SliderModel slide = new SliderModel() { Active = objSlide.Active.Value, Imagelink = objSlide.ImageLink, Name = objSlide.Name, OfferHeading = objSlide.OfferHeading, OfferText = objSlide.Offer, SliderID = objSlide.SliderID, Order = objSlide.SlideOrder.Value }; return View(slide); } } else { } return View(); }
public ActionResult Edit(int id = -1) { if (id != -1) { using (_dbContext = new karrykartEntities()) { var objSlide = _dbContext.Sliders.Find(id); SliderModel slide = new SliderModel() { Active = objSlide.Active.Value, Imagelink = objSlide.ImageLink, Name = objSlide.Name, OfferHeading = objSlide.OfferHeading, OfferText = objSlide.Offer, SliderID = objSlide.SliderID, Order = objSlide.SlideOrder.Value }; return(View(slide)); } } else { } return(View()); }
public ActionResult DeleteProductSizeMapping(Guid ProductID, int SizeID) { if (ProductID != null) { _dbContext = new karrykartEntities(); var productSizeMapping = _dbContext.ProductSizeMappings.Where(x => x.ProductID == ProductID && x.SizeID == SizeID).FirstOrDefault(); _dbContext.Entry(productSizeMapping).State = EntityState.Deleted; var productPrice = _dbContext.ProductPrices.Where(x => x.ProductID == ProductID && x.SizeID == SizeID).FirstOrDefault(); _dbContext.Entry(productPrice).State = EntityState.Deleted; var productSC = _dbContext.ProductShippings.Where(x => x.ProductID == ProductID && x.SizeID == SizeID).FirstOrDefault(); _dbContext.Entry(productSC).State = EntityState.Deleted; _dbContext.SaveChanges(); _dbContext = null; _logger.WriteLog(CommonHelper.MessageType.Success, "Product stock, price and size mapping details has been deleted successfully.", "DeleteProductSizeMapping", "ProductController", User.Identity.Name); return(Json(new { messagetype = ApplicationMessages.Product.SUCCESS, message = "Product stock, price and size mapping details has been deleted successfully." })); } return(View()); }
public UserDetails(User user, karrykartEntities context, int AddressID = -1) { this.UserID = user.UserID; this.Email = user.EmailAddress; this.FirstName = user.UserDetails.First().FirstName; this.LastName = user.UserDetails.First().LastName; this.Phone = user.Mobile; this.AddressList = new List <UserAddress>(); if (user.UserAddressDetails.Count > 0) { foreach (var userAddress in user.UserAddressDetails) { if (AddressID != -1) { if (userAddress.AddressID == AddressID) { if (!string.IsNullOrEmpty(userAddress.AddressLine1)) { this.AddressList.Add(new UserAddress(userAddress, context)); } } } else { if (!string.IsNullOrEmpty(userAddress.AddressLine1)) { this.AddressList.Add(new UserAddress(userAddress, context)); } } } } }
public ActionResult AddImageFeatureDetails(ProductModel model) { using (_dbContext = new karrykartEntities()) { if (!(String.IsNullOrEmpty(model.Features))) { foreach (var featureText in model.Features.Split(';')) { _dbContext.ProductFeatures.Add(new ProductFeature() { Feature = featureText, ProductID = model.ProductID }); } } var lstImages = UploadImage(model); foreach (var image in lstImages) { if (!String.IsNullOrEmpty(image)) { _dbContext.ProductImages.Add(new ProductImage() {ImageID=Guid.NewGuid(), ImageLink = image, ProductID = model.ProductID }); _dbContext.SaveChanges(); } } _logger.WriteLog(CommonHelper.MessageType.Success, "Product imgaes and features added successfully with name=" + model.ProductID, "Create", "ProductController", User.Identity.Name); return RedirectToAction("AddStockPrice", "Product", new { id = model.ProductID }); } return View(model); }
public ActionResult Edit(SliderModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { var slide = _dbContext.Sliders.Find(model.SliderID); if (slide != null) { slide.Active = model.Active; slide.Name = model.Name; slide.Offer = model.OfferText; slide.OfferHeading = model.OfferHeading; slide.ImageLink = model.Image.ContentLength > 0 ?CommonHelper.UploadFile(model.Image, _sliderDirectory):model.Imagelink; _dbContext.Entry(slide).State = System.Data.Entity.EntityState.Modified; _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "The image has been edited successfully,Slider ID= " + model.SliderID, "Edit", "SliderController", User.Identity.Name); Success("The image has been edited successfully, with ID = " + slide.SliderID, true); } else { } } } return(View()); }
public ProductModel GetProductDetail(Guid Id) { ProductModel objProduct = null; _context = new karrykartEntities(); var product = _context.Products.Find(Id); if (product != null) { objProduct = new ProductModel() { Active = product.Active.Value, BrandID = product.BrandID.Value, BrandName = product.Brand.Name, CategoryID = product.CategoryID.Value, CategoryName = product.Category.Name, CreatedBy = product.CreatedBy, CreatedOn = product.CreatedOn.Value, Description = product.Description, Features = GetProductFeatures(product), Images = GetProductImages(product), Name = product.Name, Prices = GetProductPrices(product), ProductID = product.ProductID, ProductSizeMappings = GetProductSizeMapping(_context, product), ShippingDetails = GetShippingDetails(product), SubCategoryID = product.SubCategoryID.Value, SubCategoryName = product.Subcategory.Name, UpdatedBy = product.UpdatedBy, UpdatedOn = product.UpdatedOn.Value }; } _context = null; return(objProduct); }
public ActionResult Edit(SliderModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { var slide = _dbContext.Sliders.Find(model.SliderID); if (slide != null) { slide.Active = model.Active; slide.Name = model.Name; slide.Offer = model.OfferText; slide.OfferHeading = model.OfferHeading; slide.ImageLink = model.Image.ContentLength > 0 ?CommonHelper.UploadFile(model.Image,_sliderDirectory):model.Imagelink; _dbContext.Entry(slide).State = System.Data.Entity.EntityState.Modified; _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "The image has been edited successfully,Slider ID= " + model.SliderID, "Edit", "SliderController", User.Identity.Name); Success("The image has been edited successfully, with ID = " + slide.SliderID, true); } else { } } } return View(); }
public void WriteLog(string messageType, string message, string methodName, string fileName, string userName) { var log = new Log() { EventTimeStamp = DateTime.UtcNow, FileName = fileName, IpAddress = GetIPAddress(), Message = message, MessageType = messageType, MethodName = methodName, UserName = userName, Browser = HttpContext.Current.Request.UserAgent }; try { _dbContext = new karrykartEntities(); _dbContext.Logs.Add(log); _dbContext.SaveChanges(); } catch (Exception ex) { } finally { _dbContext = null; } }
public ActionResult AddImageFeatureDetails(ProductModel model) { using (_dbContext = new karrykartEntities()) { if (!(String.IsNullOrEmpty(model.Features))) { foreach (var featureText in model.Features.Split(';')) { _dbContext.ProductFeatures.Add(new ProductFeature() { Feature = featureText, ProductID = model.ProductID }); } } var lstImages = UploadImage(model); foreach (var image in lstImages) { if (!String.IsNullOrEmpty(image)) { _dbContext.ProductImages.Add(new ProductImage() { ImageID = Guid.NewGuid(), ImageLink = image, ProductID = model.ProductID }); _dbContext.SaveChanges(); } } _logger.WriteLog(CommonHelper.MessageType.Success, "Product imgaes and features added successfully with name=" + model.ProductID, "Create", "ProductController", User.Identity.Name); return(RedirectToAction("AddStockPrice", "Product", new { id = model.ProductID })); } return(View(model)); }
public ActionResult AddProductStockPrice(Guid ProductID, int SizeID, string SizeName, int UnitID, int SizeTypeID, int Stock, decimal Cost, decimal Price) { if (ProductID != null) { _dbContext = new karrykartEntities(); var productSizeMapping = _dbContext.ProductSizeMappings.Where(x => x.ProductID == ProductID && x.SizeID == SizeID && x.UnitID == UnitID).FirstOrDefault(); if (productSizeMapping == null) { productSizeMapping = new ProductSizeMapping(); productSizeMapping.ProductID = ProductID; productSizeMapping.SizeID = SizeID; productSizeMapping.Stock = Stock; productSizeMapping.UnitID = UnitID; _dbContext.Entry(productSizeMapping).State = EntityState.Added; } else { return(Json(new { messagetype = ApplicationMessages.Product.ERROR, message = "Product and size mapping details already exists." })); } var price = _dbContext.ProductPrices.Where(x => x.ProductID == ProductID && x.SizeID == SizeID && x.UnitID == UnitID).FirstOrDefault(); if (price == null) { price = new ProductPrice(); price.Price = Price; price.SizeID = SizeID; price.ProductID = ProductID; price.CurrencyID = 1; price.UnitID = UnitID; _dbContext.Entry(price).State = EntityState.Added; } else { return(Json(new { messagetype = ApplicationMessages.Product.ERROR, message = "Product's size and Price mapping details already exists." })); } var shipping = _dbContext.ProductShippings.Where(x => x.SizeID == SizeID && x.ProductID == ProductID && x.UnitID == UnitID).FirstOrDefault(); if (shipping == null) { shipping = new ProductShipping(); shipping.Cost = Cost; shipping.SizeID = SizeID; shipping.ProductID = ProductID; shipping.UnitID = UnitID; _dbContext.Entry(shipping).State = EntityState.Added; } else { return(Json(new { messagetype = ApplicationMessages.Product.ERROR, message = "Product size and shipping cost mapping details already exists." })); } _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "Product stock, price and size mapping details has been added successfully.", "EditProductStockPrice", "ProductController", User.Identity.Name); return(Json(new { messagetype = ApplicationMessages.Product.SUCCESS, message = "Product stock, price and size mapping details has been added successfully." })); } return(View()); }
public ActionResult Edit(int id=-1) { using (_dbContext = new karrykartEntities()) { var brand = _dbContext.Brands.Find(id); return View(new BrandModel() { BrandID=brand.BrandID,Name= brand.Name}); } return View(); }
public JsonResult GetBrands() { _dbContext = new karrykartEntities(); var brands = _dbContext.Brands.Select(x => new { x.BrandID, x.Name }).ToList(); _dbContext = null; return(Json(brands, JsonRequestBehavior.AllowGet)); }
// // GET: /Country/ public ActionResult Index() { using (_dbContext = new karrykartEntities()) { return(View(_dbContext.Countries.ToList())); } return(View()); }
// // GET: /Country/ public ActionResult Index() { using (_dbContext = new karrykartEntities()) { return View(_dbContext.Countries.ToList()); } return View(); }
public JsonResult GetCategories() { _dbContext = new karrykartEntities(); var categories = _dbContext.Categories.Select(x => new { x.CategoryID, x.Name }).ToList(); _dbContext = null; return(Json(categories, JsonRequestBehavior.AllowGet)); }
public bool ValidateUser(UserModel model) { using (_context = new karrykartEntities()) { var p = EncryptionManager.ConvertToUnSecureString(EncryptionManager.EncryptData(model.pwd)); return(_context.Users.Any(x => x.EmailAddress == model.user && x.Password == p)); } }
// // GET: /ProductSettings/ public ActionResult UnitDetails() { using (_dbContext = new karrykartEntities()) { return(View(_dbContext.Units.ToList())); } return(View()); }
void CreateViewBagForProduct() { _dbContext = new karrykartEntities(); ViewBag.CategoryID = new SelectList(_dbContext.Categories.ToList(), "CategoryID", "Name"); ViewBag.SubcategoryID = new SelectList(_dbContext.Subcategories.ToList(), "SCategoryID", "Name"); ViewBag.BrandID = new SelectList(_dbContext.Brands.ToList(), "BrandID", "Name"); _dbContext = null; }
public User IsAuthenticatedUser(LoginModel model) { _context = new karrykartEntities(); model.UserPwd = EncryptionManager.ConvertToUnSecureString(EncryptionManager.EncryptData(model.UserPwd)); var user = _context.Users.Where(x => x.EmailAddress == model.UserID || x.Mobile == model.UserID).FirstOrDefault(); _context = null; return((user != null) ? (user.Active.Value && user.Password == model.UserPwd) ? user : null : null); }
public ActionResult AddStockPrice(Guid id) { using (_dbContext = new karrykartEntities()) { var product = _dbContext.Products.Find(id); return View(new ProductStockPriceModel() { ProductID = product.ProductID, Name = product.Name }); } return View(); }
public ActionResult Details(Guid id) { using (_dbContext = new karrykartEntities()) { _productHelper = new ProductHelper(); return(View(_productHelper.GetProduct(id))); } return(View()); }
void CreateViewBagForStockPrice() { _dbContext = new karrykartEntities(); ViewBag.UnitID = new SelectList(_dbContext.Units.ToList(), "UnitID", "Name"); ViewBag.SizeTypeID = new SelectList(_dbContext.SizeTypes.ToList(), "SizeTypeID", "Name"); ViewBag.CurrencyID = new SelectList(_dbContext.Currencies.ToList(), "CurrencyID", "Shortform"); ViewBag.SizeID = new SelectList(_dbContext.Sizes.ToList(), "SizeID", "Name"); _dbContext = null; }
public JsonResult GetUnits() { _dbContext = new karrykartEntities(); var units = _dbContext.Units.Select(x => new { x.UnitID, x.Name }).ToList(); _dbContext = null; return(Json(units, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit(int id = -1) { using (_dbContext = new karrykartEntities()) { var category = _dbContext.Categories.Find(id); return View(new CategoryModel {CategoryID=category.CategoryID,Name=category.Name }); } return View(); }
public JsonResult GetSizeTypes() { _dbContext = new karrykartEntities(); var sizetypes = _dbContext.SizeTypes.Select(x => new { x.SizeTypeID, x.Name }).ToList(); _dbContext = null; return(Json(sizetypes, JsonRequestBehavior.AllowGet)); }
public ActionResult AddImageFeatureDetails(Guid id) { using (_dbContext = new karrykartEntities()) { var product = _dbContext.Products.Find(id); return View(new ProductModel() { ProductID = product.ProductID, Name = product.Name }); } return View(); }
public static void SaveOTP(string otp, string assignedTo) { var dbContext = new karrykartEntities(); dbContext.OTPHolders.Add(new OTPHolder() { OTPValue = otp, OTPAssignedTo = assignedTo }); dbContext.SaveChanges(); dbContext = null; }
public ActionResult Create(CountryModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { _dbContext.Countries.Add(new Country() { CountryName = model.Name }); _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "New country successfully with Name=" + model.Name, "Create", "CountryController", User.Identity.Name); Success("A new country is added successfully.", true); return RedirectToAction("Index", "Country"); } } return View(); }
public ActionResult Create(BrandModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { var brand = new Brand(); brand.Name = model.Name; _dbContext.Brands.Add(brand); _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "Brand add successfully with id=" + brand.BrandID, "Create", "BrandController", User.Identity.Name); Success("The brand is added successfully.", true); return RedirectToAction("Index", "Brand"); } } return View(); }
public ActionResult Edit(BrandModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { var brand = _dbContext.Brands.Find(model.BrandID); brand.Name = model.Name; _dbContext.Entry(brand).State = System.Data.Entity.EntityState.Modified; _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "The brand is edited successfully with id=" + brand.BrandID, "Edit", "BrandController", User.Identity.Name); Success("The brand is edit successfully.", true); return RedirectToAction("Index", "Brand"); } } return View(model); }
public ActionResult Create(CategoryModel model) { if (ModelState.IsValid) { var category = new Category(); category.Name = model.Name; using (_dbContext = new karrykartEntities()) { _dbContext.Categories.Add(category); _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "Category created successfully with categoryID=" + category.CategoryID, "Create", "CategoryController", User.Identity.Name); Success("Category is created successfully.", true); return RedirectToAction("Index", "Category"); } } return View(); }
public ActionResult Createsubcategory(int id = -1) { using (_dbContext = new karrykartEntities()) { var category = _dbContext.Categories.Find(id); if(category!=null) { var subcategoryModel = new SubcategoryModel(); subcategoryModel.CategoryName = category.Name; subcategoryModel.CategoryID = category.CategoryID; return View(subcategoryModel); } } return View(); }
public ActionResult Createsubcategory(SubcategoryModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { var Subcategory = new Subcategory(); Subcategory.CategoryID = model.CategoryID; Subcategory.Name = model.Name; _dbContext.Subcategories.Add(Subcategory); _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success,"New sub category added successfully with id="+Subcategory.SCategoryID,"CreateSubcategory","CategoryController",User.Identity.Name); Success("Subcategory added successfully"); return RedirectToAction("Subcategory", "Category", new { id = model.CategoryID }); } } return View(model); }
public ActionResult Subcategory(int id = -1) { using (_dbContext = new karrykartEntities()) { ViewBag.CategoryID = id; ViewBag.Category = _dbContext.Categories.Find(id).Name; return View(_dbContext.Subcategories.Where(x=>x.CategoryID == id).ToList()); } return View(); }
public ActionResult Edit(CategoryModel model) { if (ModelState.IsValid) { using (_dbContext =new karrykartEntities()) { var category = _dbContext.Categories.Find(model.CategoryID); category.Name = model.Name; _dbContext.Entry(category).State = System.Data.Entity.EntityState.Modified; _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "The category has been edited successfully,category ID= " + model.CategoryID, "Edit", "CategoryController", User.Identity.Name); Success("The category has been edited successfully.", true); return RedirectToAction("Index", "Category"); } } return View(); }
public JsonResult GetSubCategories(int id) { _dbContext = new karrykartEntities(); var subcategories = _dbContext.Subcategories.Where(x => x.CategoryID == id).Select(x => new { x.SCategoryID,x.Name }).ToList(); _dbContext = null; return Json(subcategories, JsonRequestBehavior.AllowGet); }
void CreateViewBagForProduct() { _dbContext = new karrykartEntities(); ViewBag.CategoryID = new SelectList(_dbContext.Categories.ToList(), "CategoryID", "Name"); ViewBag.SubcategoryID = new SelectList(_dbContext.Subcategories.ToList(), "SCategoryID", "Name"); ViewBag.BrandID = new SelectList(_dbContext.Brands.ToList(), "BrandID", "Name"); _dbContext = null; }
public ActionResult Create(ProductModel model) { if (ModelState.IsValid) { using (_dbContext = new karrykartEntities()) { var product = new Product() { Active = model.Active, CategoryID = model.CategoryID, CreatedBy = User.Identity.Name, UpdatedBy = User.Identity.Name, Description = model.Description, Name = model.Name, ProductID = Guid.NewGuid(), SubCategoryID = model.SubCategoryID, BrandID = model.BrandID, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }; _dbContext.Products.Add(product); _dbContext.SaveChanges(); _logger.WriteLog(CommonHelper.MessageType.Success, "Product created successfully with name=" + product.ProductID, "Create", "ProductController", User.Identity.Name); return RedirectToAction("AddImageFeatureDetails", "Product", new { id = product.ProductID }); } } CreateViewBagForProduct(); return View(); }