public bool Add(ProductAddView model) { try { Product product = new Product(); product.Avatar = "http://localhost:44351" + model.Avatar; product.Category = model.Category; product.Content = model.Content.Replace("\"/Content/FileUploads/", "\"http://localhost:44351/Content/FileUploads/"); product.CreateBy = model.Staff.ToString(); product.CreateDate = DateTime.Now; product.Desc = model.Desc; product.ModifyBy = model.Staff.ToString(); product.ModifyDate = DateTime.Now; product.Price = model.Price; product.Status = model.Status; product.Title = model.Title; product.Staff = model.Staff; DbContext.Products.Add(product); return(true); } catch (System.Exception) { return(false); } }
public ActionResult Add(ProductAddView model) { try { if (ModelState.IsValid) { HttpCookie reqCookies = Request.Cookies["StaffLoginCookie"]; ResponseStaffLogin login = JsonConvert.DeserializeObject <ResponseStaffLogin>(reqCookies.Value.ToString().UrlDecode()); if (login == null) { return(Redirect("/System/Login")); } model.Vendor = login.ID; if (_productBusiness.Add(model)) { _productBusiness.Save(); return(RedirectToAction("List")); } } ViewBag.CategoryLst = _productCategoryBusiness.GetAll(); return(View()); } catch (Exception) { ViewBag.CategoryLst = _productCategoryBusiness.GetAll(); return(View()); } }
public static ProductAddView AddProduct(int CategoryId) { ProductAddView product = new ProductAddView(); if (CategoryId == 1)// car { product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "Model", EditorType = "DropDown", ValueType = "string", IsMandatory = true, ValueEnum = new List <string> { "Toyota", "Mazda", "Ford", "BMW" } }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "Type", EditorType = "DropDown", ValueType = "string", IsMandatory = true, ValueEnum = new List <string> { }, DependsOn = "Model" }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "Name", EditorType = "TextBox", ValueType = "string", IsMandatory = true }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "Description", EditorType = "TextArea", ValueType = "string", IsMandatory = true }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "Color", EditorType = "DropDown", ValueType = "string", IsMandatory = true, ValueEnum = new List <string> { "Red", "Green", "Yellow" } }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "Aumatic", EditorType = "CheckBox", ValueType = "bool", IsMandatory = true }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "Fuel", EditorType = "RadioButton", ValueType = "string", ValueEnum = new List <string> { "Petrol", "Disel", "LPG" } }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "KilioMetere", EditorType = "TextBox", ValueType = "string" }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "FeulConsumption", EditorType = "TextBox", ValueType = "string", IsMandatory = true }); } if (CategoryId == 2)//Mobile { product.Features.Add(new ProductFeatureAdd { ProductId = 4, FeatureName = "Name", EditorType = "TextBox", ValueType = "string", IsMandatory = true }); product.Features.Add(new ProductFeatureAdd { ProductId = 4, FeatureName = "Description", EditorType = "TextBox", ValueType = "string", IsMandatory = true }); product.Features.Add(new ProductFeatureAdd { ProductId = 4, FeatureName = "Color", EditorType = "DropDown", ValueType = "string", IsMandatory = true, ValueEnum = new List <string> { "Black", "White", "Red" } }); product.Features.Add(new ProductFeatureAdd { ProductId = 4, FeatureName = "Model", EditorType = "DropDown", ValueType = "string", IsMandatory = true, ValueEnum = new List <string> { "Iphone", "Samsung", "HTC" } }); product.Features.Add(new ProductFeatureAdd { ProductId = 4, FeatureName = "Type", EditorType = "DropDown", ValueType = "string", IsMandatory = true, DependsOn = "Model" }); product.Features.Add(new ProductFeatureAdd { ProductId = 4, FeatureName = "Battery Life", EditorType = "TextBox", ValueType = "string", IsMandatory = true }); product.Features.Add(new ProductFeatureAdd { ProductId = 3, FeatureName = "HeadSet", EditorType = "CheckBox", ValueType = "bool", IsMandatory = true }); } return(product); }
public bool Add(ProductAddView entity) { return(_product.Add(entity)); }