// GET: Backend/MemberShipSetting public ActionResult List(long SiteID, long MenuID) { ViewBag.SiteID = SiteID; ViewBag.MenuID = MenuID; ViewBag.UploadVPath = UpdFileInfo.GetVPathByMenuID(SiteID, MenuID); List <CategoryModels> identity_items = CategoryDAO.GetItems(IdentityType); if (identity_items != null && identity_items.Count() > 0) { ViewBag.ListIdentity = identity_items; } else { //20181025 nina 身分沒有資料時,新增一般會員 CategoryModels category = new CategoryModels() { Type = IdentityType, Title = "一般會員", ShowStatus = true, MemberSession = (int)MemberSession.限制, PresetIdentity = (int)PresetIdentity.一般會員 }; CategoryDAO.SetItem(category); ViewBag.ListIdentity = CategoryDAO.GetItems(IdentityType); } List <CategoryModels> favority_items = CategoryDAO.GetItems(FavorityType); ViewBag.ListFavoity = favority_items; return(View()); }
public ActionResult FavorityEdit(long SiteID, long MenuID, CategoryModels model, HttpPostedFileBase fIcon, string fIconBase64) { ViewBag.SiteID = SiteID; ViewBag.MenuID = MenuID; ViewBag.UploadVPath = UpdFileInfo.GetVPathByMenuID(SiteID, MenuID); if (string.IsNullOrEmpty(model.Icon)) { model.Icon = string.Empty; } else { ImageModel imgModel = JsonConvert.DeserializeObject <ImageModel>(model.Icon); if (imgModel.ID == 0) { if (fIcon == null || fIcon.ContentLength == 0) { model.Icon = string.Empty; } else { string fileName = Golbal.UpdFileInfo.SaveFilesByMenuID(fIcon, SiteID, MenuID, fIconBase64); imgModel.ID = 1; imgModel.Img = fileName; model.Icon = JsonConvert.SerializeObject(imgModel); } } } CategoryDAO.SetItem(model); ViewBag.Exit = true; return(View(model)); }
public ActionResult Create(Category cate) { try { ICategoryService cateSrv = IoC.Resolve <ICategoryService>(); int c = cateSrv.Query.Where(p => p.NameVNI == cate.NameVNI || p.NameENG == cate.NameENG || p.UrlName == cate.UrlName).Count(); if (c > 0) { Messages.AddErrorMessage("Tiêu đề hoặc đường dẫn cho chuyên mục đã tồn tại."); CategoryModels model = new CategoryModels(); model.ArtCategory = cate; model.ParentCategory = cateSrv.Query.Where(p => p.ParentID == 0).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList(); return(View(model)); } cate.CreatedBy = HttpContext.User.Identity.Name; cateSrv.CreateNew(cate); cateSrv.CommitChanges(); Messages.AddFlashMessage("Thêm mới thành công."); logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Category - Create :" + cate.Id, "Create Category Success", LogType.Success, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); return(RedirectToAction("Index")); } catch (Exception ex) { logSrv.CreateNew(FXContext.Current.CurrentUser.userid, "Category - Create :" + cate.Id, "Create Category Error :" + ex, LogType.Error, HttpContext.Request.UserHostAddress, HttpContext.Request.Browser.Browser); Messages.AddErrorMessage("Có lỗi xảy ra, vui lòng thực hiện lại."); ICategoryService artCateSrv = IoC.Resolve <ICategoryService>(); CategoryModels model = new CategoryModels(); model.ArtCategory = cate; model.ParentCategory = artCateSrv.Query.Where(p => p.ParentID == 0).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList(); return(View(model)); } }
public ActionResult EditCategory(int id) { AppDbContext dbContext = new AppDbContext(); CategoryModels category = dbContext.getCategories.SingleOrDefault(c => c.CategoryId == id); return(View(category)); }
public ActionResult Edit(long SiteID, long MenuID, CategoryModels model) { if (!string.IsNullOrWhiteSpace(model.Image)) { WorkV3.Models.ResourceImagesModels imgModel = JsonConvert.DeserializeObject <WorkV3.Models.ResourceImagesModels>(model.Image); if (imgModel.ID == 0) { // 新上傳的圖片 HttpPostedFileBase postedFile = Request.Files["fImage"]; if (postedFile == null || postedFile.ContentLength == 0) { model.Image = string.Empty; } else { model.Image = Golbal.UpdFileInfo.SaveFilesByMenuID(postedFile, SiteID, MenuID); } } else { model.Image = imgModel.Img; } } if (model.PresetIdentity == (int)PresetIdentity.一般會員) { model.MemberSession = (int)MemberSession.限制; } ViewBag.SiteID = SiteID; ViewBag.MenuID = MenuID; ViewBag.UploadVPath = UpdFileInfo.GetVPathByMenuID(SiteID, MenuID); CategoryDAO.SetItem(model); ViewBag.Exit = true; return(View(model)); }
public static List <CategoryModels> GetItems(string Type, string Ids = "") { List <CategoryModels> items = new List <CategoryModels>(); string sql = "SELECT * FROM Categories WHERE 1=1 "; if (!string.IsNullOrEmpty(Type)) { sql += $"AND (Type='" + Type.Replace(",", "','") + "') "; } if (!string.IsNullOrWhiteSpace(Ids)) { sql += $"AND ID in ({Ids}) "; } SQLData.Database db = new SQLData.Database(WebInfo.Conn); DataTable datas = db.GetDataTable(sql); foreach (DataRow dr in datas.Rows) { CategoryModels m = new CategoryModels(); m.ID = (long)dr["ID"]; m.Type = dr["Type"].ToString().Trim(); m.Title = dr["Title"].ToString().Trim(); m.RemarkText = dr["RemarkText"].ToString().Trim(); m.ShowStatus = Convert.ToBoolean(dr["ShowStatus"].ToString()); m.Icon = dr["Icon"].ToString().Trim(); m.Sort = Convert.ToInt32(dr["Sort"].ToString()); m.Image = dr["Image"].ToString().Trim(); m.MemberSession = (!string.IsNullOrWhiteSpace(dr["MemberSession"].ToString()) ? Convert.ToInt32(dr["MemberSession"].ToString()) : 0); items.Add(m); } return(items); }
public static void SetItem(CategoryModels item) { long creator = MemberDAO.SysCurrent.Id; SQLData.Database db = new SQLData.Database(WebInfo.Conn); string sql = "Select 1 From [Categories] Where ID = " + item.ID; item.Icon = item.Icon == null ? "" : item.Icon; bool isNew = db.GetFirstValue(sql) == null; if (isNew) { using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(WebInfo.Conn)) { sql = $"IF not EXISTS (SELECT 1 FROM Categories WHERE ID = @ID)"; sql += $" INSERT INTO [Categories]([ID],[Type],[Title],[RemarkText],[ShowStatus],[Icon],[Sort],[Creator],[CreateTime] ,[Modifier],[ModifyTime],[Image],[MemberSession],[PresetIdentity]) VALUES({ WorkLib.GetItem.NewSN() },@Type,@Title,@RemarkText, @ShowStatus, @Icon, @Sort ,{creator}, getdate(),{creator}, getdate(),@Image,@MemberSession,@PresetIdentity) "; conn.Execute(sql, item); } } else { using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(WebInfo.Conn)) { sql = $"UPDATE Categories SET [Title]=@Title,[RemarkText]=@RemarkText, [ShowStatus]=@ShowStatus,[Icon]=@Icon,[Sort]=@Sort,[Modifier]={creator},ModifyTime=getdate(),[Image]=@Image,[MemberSession]=@MemberSession"; sql += " WHERE ID=@ID "; conn.Execute(sql, item); } } }
public ActionResult Edit(int id, CategoryModels requestCategory) { try { if (ModelState.IsValid) { CategoryModels cat = db.Categories.Find(id); if (TryUpdateModel(cat)) { cat.CategoryName = requestCategory.CategoryName; TempData["message"] = Licenta_V0.Resources.ErrorAndConfirmMessages.ConfirmCategoryModify; db.SaveChanges(); } return(RedirectToAction("Index")); } else { return(View(requestCategory)); } } catch (Exception e) { return(View(requestCategory)); } }
public async Task <IHttpActionResult> PutCategoryModels(int id, CategoryModels categoryModels) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != categoryModels.Id) { return(BadRequest()); } db.Entry(categoryModels).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryModelsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult DeleteConfirmed(int id) { CategoryModels categoryModels = db.CategoryModels.Find(id); db.CategoryModels.Remove(categoryModels); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Category(string category, CategoryModels model) //в модели есть лист значений чекбоксов model.Check { GetFilteringValues(category, model); GetFilters(category); GetSortedCategories(category, model); ViewBag.Max = GetMaxPrice(category); ViewBag.Sorted = model.Method; return(View()); }
public ActionResult Delete(int id) { CategoryModels cat = db.Categories.Find(id); db.Categories.Remove(cat); TempData["message"] = Licenta_V0.Resources.ErrorAndConfirmMessages.ConfirmCategoryDeleted; db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create() { ICategoryService artCateSrv = IoC.Resolve <ICategoryService>(); CategoryModels model = new CategoryModels(); model.ArtCategory = new Category(); model.ArtCategory.Active = true; model.ParentCategory = artCateSrv.Query.Where(p => p.ParentID == 0).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList(); return(View(model)); }
public ActionResult Edit([Bind(Include = "ID,categoryName")] CategoryModels categoryModels) { if (ModelState.IsValid) { db.Entry(categoryModels).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoryModels)); }
public ActionResult Index(int?page) { AppDbContext dbContext = new AppDbContext(); ListProductViewModel listProduct = new ListProductViewModel(); listProduct.Brands = dbContext.getBrands.ToList(); List <ProductModels> products = dbContext.getProducts.ToList(); List <GetProductViewModel> getProducts = new List <GetProductViewModel>(); /*Get products details*/ foreach (var item in products) { ModelModels model = dbContext.getModels.SingleOrDefault(m => m.Id == item.ModelId); BrandModels brand = dbContext.getBrands.SingleOrDefault(b => b.BrandId == model.BrandId); CategoryModels category = dbContext.getCategories.SingleOrDefault(c => c.CategoryId == model.CategoryId); GetProductViewModel getProduct = new GetProductViewModel { Id = item.Id, Name = model.Name, Brand = brand.Brand, Category = category.Category, Price = item.Price, Color = item.Color, Storage = item.Storage, Processor = item.Processor, Memory = item.Memory, Display = item.Display, Details = item.Details, CreatedBy = item.CreatedBy, CreatedDate = item.CreatedDate }; getProduct.Photos = dbContext.getProductPhotos(item.Id).ToList(); getProducts.Add(getProduct); } /*Search product and sort by date*/ listProduct.Products = getProducts.OrderByDescending(p => p.CreatedDate).ToList().ToPagedList(page ?? 1, 20); /*Get the number of each product in a brand*/ listProduct.EachProductsOfBrands = new List <int>(); foreach (var brand in listProduct.Brands) { List <ProductModels> productsOfBrands = dbContext.getProductBrands(brand.BrandId).ToList(); int numberOfBrand = productsOfBrands.Count; listProduct.EachProductsOfBrands.Add(numberOfBrand); } /*Create Index view with product details*/ return(View(listProduct)); }
public ActionResult Edit(CategoryModels model) { try { if (!ModelState.IsValid) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } string msg = ""; model.CreatedUser = CurrentUser.UserId; var result = _factory.UpdateCategory(model, ref msg); if (result) { HttpCookie _LocationCookie = Request.Cookies["CateCookie"]; //if (_LocationCookie == null) //{ // HttpCookie cookie = new HttpCookie("CateCookie"); // cookie.Expires = DateTime.Now.AddYears(10); //} CategoryFactory _facLoc = new CategoryFactory(); var _loc = _facLoc.GetListCategory().Select(x => new CateSession { Id = x.ID, Name = x.Name }).ToList(); if (_loc != null && _loc.Any()) { string myObjectJson = JsonConvert.SerializeObject(_loc); //new JavaScriptSerializer().Serialize(userSession); HttpCookie cookie = new HttpCookie("CateCookie"); cookie.Expires = DateTime.Now.AddYears(10); cookie.Value = Server.UrlEncode(myObjectJson); Response.Cookies.Add(cookie); } return(RedirectToAction("Index")); } else { model = GetDetail(model.ID); if (!string.IsNullOrEmpty(msg)) { ModelState.AddModelError("Name", msg); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } } catch (Exception ex) { NSLog.Logger.Error("Category_Edit: ", ex); ModelState.AddModelError("Name", ex.Message); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } }
public ActionResult Create([Bind(Include = "ID,categoryName")] CategoryModels categoryModels) { if (ModelState.IsValid) { db.CategoryModels.Add(categoryModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoryModels)); }
public async Task <IHttpActionResult> GetCategoryModels(int id) { CategoryModels categoryModels = await db.CategoryModels.FindAsync(id); if (categoryModels == null) { return(NotFound()); } return(Ok(categoryModels)); }
public IHttpActionResult GetCategories(string emailId) { List <CategoryModels> listOfCategories = new List <CategoryModels>(); CategoryModels categoryModel = new CategoryModels(); categoryModel.emailId = emailId; try { if (sqlConnection == null || sqlConnection.State == System.Data.ConnectionState.Closed) { sqlConnection = SQLHelperClasses.SqlHelper.OpenConnection(); } cmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); cmd.Connection = sqlConnection; cmd.CommandType = System.Data.CommandType.StoredProcedure; const string storedProcedure = "GetCategories"; cmd.CommandText = storedProcedure; SqlParameter paramEmail = new SqlParameter(); paramEmail.ParameterName = "@EmailId"; paramEmail.Direction = System.Data.ParameterDirection.Input; paramEmail.SqlDbType = System.Data.SqlDbType.VarChar; paramEmail.Size = 50; paramEmail.Value = categoryModel.emailId; cmd.Parameters.AddRange(new SqlParameter[] { paramEmail }); da.Fill(dt); int rows = dt.Rows.Count; if (rows > 0) { for (int i = 0; i < rows; i++) { categoryModel = new CategoryModels(); categoryModel.categoryDescription = dt.Rows[i]["CategoryDescription"].ToString(); categoryModel.categoryName = dt.Rows[i]["CategoryName"].ToString(); categoryModel.isActive = (bool)dt.Rows[i]["Active"]; listOfCategories.Add(categoryModel); } return(Ok(listOfCategories)); } else { HttpError error = new HttpError("No Rows found"); var responseMessage = Request.CreateErrorResponse(HttpStatusCode.NotFound, error); throw new HttpResponseException(responseMessage); } } catch (Exception exception) { throw new Exception(exception.ToString()); } }
public ActionResult Create([Bind(Include = "Id,Name,Description")] CategoryModels categoryModels) { if (ModelState.IsValid) { categoryModels.UserName = HttpContext.User.Identity.Name; db.CategoryModels.Add(categoryModels); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(categoryModels)); }
public ActionResult AddCategory(CategoryModels Category) { var CategoryModel = new CategoryModels { Name = Category.Name }; DbContext.Categories.Add(CategoryModel); DbContext.SaveChanges(); return(RedirectToAction("Index", "Categories")); }
public ActionResult Edit(int id) { ICategoryService artCateSrv = IoC.Resolve <ICategoryService>(); CategoryModels model = new CategoryModels(); model.ArtCategory = artCateSrv.Getbykey(id); IArticlesService artSrv = IoC.Resolve <IArticlesService>(); model.articleNumbers = artSrv.Query.Where(p => p.CategoryID == id).Count(); model.ParentCategory = artCateSrv.Query.Where(p => p.ParentID == 0).OrderBy(p => p.NameVNI).ThenBy(p => p.NameENG).ToList(); return(View(model)); }
public async Task <IHttpActionResult> PostCategoryModels(CategoryModels categoryModels) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CategoryModels.Add(categoryModels); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = categoryModels.Id }, categoryModels)); }
private SectionModel MapSection(Section section) { var sectionModel = new SectionModel { Name = section.Name, Categories = section.Categories .Where(c => c.Visible) .Select(c => CategoryModels.FirstOrDefault(i => i.Id == c.Id)) .ToArray() }; return(sectionModel); }
public CategoryModels GetDetail(string id) { try { CategoryModels model = _factory.GetDetailCategory(id); return(model); } catch (Exception ex) { NSLog.Logger.Error("GetDetailCategory: ", ex); return(null); } }
public async Task <IHttpActionResult> DeleteCategoryModels(int id) { CategoryModels categoryModels = await db.CategoryModels.FindAsync(id); if (categoryModels == null) { return(NotFound()); } db.CategoryModels.Remove(categoryModels); await db.SaveChangesAsync(); return(Ok(categoryModels)); }
// GET: Category/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CategoryModels categoryModels = db.CategoryModels.Find(id); if (categoryModels == null) { return(HttpNotFound()); } return(View(categoryModels)); }
public ActionResult AddCategory(CategoryModels model) { if (ModelState.IsValid) { AppDbContext dbContext = new AppDbContext(); CategoryModels category = new CategoryModels { Category = model.Category, CategoryDetails = model.CategoryDetails + "_create by " + User.Identity.Name + " on " + DateTime.Now }; dbContext.addCategory(category); return(RedirectToAction("Index")); } return(View()); }
private string GetInsertString(string category, CategoryModels model) { var accordances = new Accordances(model.Check, ViewBag.Dictionary, category); string result = "and("; Dictionary <string, List <long> > structure = new Dictionary <string, List <long> >(); for (int i = 0; i < accordances.Check.Count; i++) { if (accordances.Check[i]) { var ids = accordances.GetIds(i); var property = accordances.GetProperty(i); if (!structure.ContainsKey(property)) { structure.Add(property, ids); } else { var currentList = structure[property]; structure[property] = currentList.Union(ids).ToList(); } } } foreach (var element in structure) { for (int i = 0; i < element.Value.Count; i++) { if (i == 0) { result += $"(id={element.Value[i]} or "; } else { result += $"id={element.Value[i]} or "; } } result = result.Remove(result.Length - 4, 4); result += ") and "; } result = result.Remove(result.Length - 5, 5); result += ")"; return(result); }
public ActionResult Products(int id) { ViewBag.ModelId = id; AppDbContext dbContext = new AppDbContext(); List <ProductModels> products = dbContext.getProductModels(id).ToList(); if (products.Count > 0) { ProductViewModel productView = new ProductViewModel(); ModelModels model = dbContext.getModels.SingleOrDefault(m => m.Id == id); BrandModels brand = dbContext.getBrands.SingleOrDefault(b => b.BrandId == model.BrandId); CategoryModels category = dbContext.getCategories.SingleOrDefault(c => c.CategoryId == model.CategoryId); foreach (var item in products.ToList()) { ProductModels product = new ProductModels { Id = item.Id, Price = item.Price, Color = item.Color, Storage = item.Storage, Processor = item.Processor, Memory = item.Memory, Display = item.Display, Details = item.Details, BrandId = item.BrandId, ModelId = item.ModelId, CreatedBy = item.CreatedBy, CreatedDate = item.CreatedDate }; List <ProductPhoto> photos = dbContext.getProductPhotos(item.Id).ToList(); product.Photos = photos; productView.Name = model.Name; productView.Brand = brand.Brand; productView.Category = category.Category; productView.Products = products; } return(View(productView)); } ViewBag.Result = "No product created"; return(View()); }