/// <summary> /// Insert new category /// </summary> /// <param name="add"></param> /// <returns></returns> public int insert(CategoryModel add) { try { Category model = new Category(); model.Name = add.Name; model.Slug = !string.IsNullOrEmpty(add.Slug) ? add.Slug : Utility.GetAlias(add.Name); model.Parent = add.Parent; model.Visible = add.Visibled; model.OrderBy = add.OrderBy; model.MetaTitle = add.MetaTitle; model.MetaKeyword = add.MetaKeyWord; model.MetaDescription = add.MetaDescription; db.Categories.Add(model); if (db.SaveChanges() > 0) { return(1); } } catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(-1); } return(0); }
/// <summary> /// Thêm mới quyền cho nhân viên /// </summary> /// <param name="lstMember"></param> /// <returns></returns> public bool Insert(List <MemberModel> lstMember, int userID) { try { db = new THN_WebApplicationEntities(); if (lstMember != null && lstMember.Count > 0) { foreach (var item in lstMember) { Member model = new Member(); model.UserID = item.UserID; model.FuncID = item.FuncID; model.CreateBy = ConfigHelper.User.Username; model.CreateDate = DateTime.Now; db.Members.Add(model); } if (db.SaveChanges() > 0) { return(true); } } return(false); }catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(false); } }
/// <summary> /// Login Website /// </summary> /// <param name="username">username or email</param> /// <param name="password">password login</param> /// <param name="login">AccountModel</param> /// <returns></returns> public bool Login(string username, string password, out AccountModel login) { try { User user = new User(); db = new THN_WebApplicationEntities(); AccountModel model = new AccountModel(); if (EmailHelper.IsEmail(username)) { user = db.Users.Where(u => u.Email == username).FirstOrDefault(); } else { user = db.Users.Where(u => u.Username.Contains(username)).FirstOrDefault(); } if (user == null) { login = model; return(false); } else { string seretKey = user.SeretKey; string pssword = Securities.EncryptPassword(password + seretKey); if (user.UPassword.Contains(pssword)) { user.IPAddress = Utility.GetClientIP(); user.LastLogin = DateTime.Now; db.SaveChanges(); model.ID = (int)user.ID; model.Username = user.Username; model.Email = user.Email; model.Name = user.Name; model.Address = user.Addrress; model.Phone = user.Mobile; model.IPAdress = user.IPAddress; model.LastDateLogin = (DateTime)user.LastLogin; } login = model; } if (login != null && !string.IsNullOrEmpty(login.Username) && login.ID > 0) { return(true); } return(false); } catch (Exception ex) { WriteLog(ex); login = new AccountModel(); return(false); } }
/// <summary> /// Add new Fucntion /// </summary> /// <param name="add"></param> /// <returns></returns> public bool Insert(Function add) { try { db = new THN_WebApplicationEntities(); db.Functions.Add(add); if (db.SaveChanges() > 0) { return(true); } return(false); }catch (Exception ex) { WriteLog(ex); return(false); } }
/// <summary> /// Edit product by ID /// </summary> /// <param name="update"></param> /// <returns></returns> public int Update(ProductModel update) { try { db = new THN_WebApplicationEntities(); Product model = db.Products.Find(update.Id); model.Name = update.Name; model.Slug = !string.IsNullOrEmpty(update.Slug) ? update.Slug : Utility.GetAlias(update.Name); model.ShortDescription = update.ShortDescription; model.Detail = update.Detail; model.Visibled = update.Visibled == true ? 1 : 0; model.IsNew = update.IsNew; model.IsHome = update.IsHome; model.IsHot = update.IsHot; model.OrderBy = update.OrderBy; model.CategoryID = update.CategoryID; model.MenufactureID = 1; model.MetaTitle = update.MetaTitle; model.MetaKeyword = update.MetaKeyword; model.MetaDescription = update.MetaDescription; model.PriceOld = update.PriceOld; model.PricceNew = update.PriceNew; model.UpdatedDate = DateTime.Now; model.UpdatedBy = AccountLogin.User.Username; if (db.SaveChanges() > 0) { if (HttpContext.Current.Request.Files.Count > 0) { string oldImage = model.Picture; DateTime timeSave = (DateTime)model.CreatedDate; string folderSave = "~/Images/product/" + timeSave.ToString("MMyyyy"); model.Picture = FileHelper.UploadImage(folderSave, model.Slug); FileHelper.delete(folderSave, oldImage); } return(1); } return(0); } catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(-1); } }
public bool Update(List <MemberModel> update, int UserID) { try { db = new THN_WebApplicationEntities(); var lst = db.Members.Where(m => m.UserID == UserID).ToList(); db.Members.RemoveRange(lst); if (db.SaveChanges() > 0) { bool rs = this.Insert(update, UserID); return(rs); } return(false); }catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(false); } }
public int UploadImages(int ProductID, string[] listImageTitle, string[] listImageAlt, string[] lstOrderBy) { try { db = new THN_WebApplicationEntities(); var product = GetByID(ProductID); if (product == null || product.ID <= 0) { return(0); } string folder = "~/Images/product/" + "P" + product.ID; List <string> lstImages = FileHelper.UploadImages(folder, product.Slug); ProductImage pm; if (lstImages.Count > 0) { var i = 0; foreach (var str in lstImages) { pm = new ProductImage(); pm.Title = !string.IsNullOrEmpty(listImageTitle[i]) ? listImageTitle[i] : product.Name; pm.AltImages = !string.IsNullOrEmpty(listImageAlt[i]) ? listImageAlt[i] : product.MetaTitle; pm.OrderBy = !string.IsNullOrEmpty(lstOrderBy[i]) ? int.Parse(lstOrderBy[i]) : (i + 1); pm.FileSave = str; pm.ProductID = product.ID; db.ProductImages.Add(pm); i = i + 1; } } if (db.SaveChanges() > 0) { return(1); } return(0); } catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(-1); } }
/// <summary> /// Update the function in database /// </summary> /// <param name="update"></param> /// <returns></returns> public bool Update(Function update) { try { db = new THN_WebApplicationEntities(); var model = db.Functions.Find(update.ID); if (model == null) { return(false); } if (db.SaveChanges() > 0) { return(true); } return(false); } catch (Exception ex) { WriteLog(ex); return(false); } }
/// <summary> /// Add new Product /// </summary> /// <param name="add"></param> /// <returns></returns> public int Insert(ProductModel add) { try { db = new THN_WebApplicationEntities(); Product model = new Product(); model.Name = add.Name; model.Slug = !string.IsNullOrEmpty(add.Slug) ? add.Slug : Utility.GetAlias(add.Name); model.ShortDescription = add.ShortDescription; model.Detail = add.Detail; model.Visibled = add.Visibled == true ? 1 : 0; model.IsNew = add.IsNew; model.IsHome = add.IsHome; model.IsHot = add.IsHot; model.OrderBy = add.OrderBy; model.CategoryID = add.CategoryID; model.MenufactureID = 1; model.MetaTitle = add.MetaTitle; model.MetaKeyword = add.MetaKeyword; model.MetaDescription = add.MetaDescription; model.CreatedDate = DateTime.Now; model.CreatedBy = AccountLogin.User.Username; model.PriceOld = add.PriceOld; model.PricceNew = add.PriceNew; string folderSave = "~/Images/product/" + DateTime.Now.ToString("MMyyyy"); model.Picture = FileHelper.UploadImages(folderSave, model.Slug)[0].ToString(); db.Products.Add(model); if (db.SaveChanges() > 0) { return(1); } return(0); } catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(-1); } }
/// <summary> /// Delete a Function /// </summary> /// <param name="id"></param> /// <returns></returns> public bool Delete(int id) { try { db = new THN_WebApplicationEntities(); var model = db.Functions.Find(id); if (model == null) { return(false); } if (db.SaveChanges() > 0) { return(true); } return(false); }catch (Exception ex) { WriteLog(ex); return(false); } //throw new NotImplementedException(); }
/// <summary> /// xoá nhân viên /// </summary> /// <param name="id"></param> /// <returns></returns> public int Delete(int id) { try { db = new THN_WebApplicationEntities(); var model = db.Users.Find(id); if (model == null) { return(-1); } db.Users.Remove(model); if (db.SaveChanges() > 0) { return(1); } return(0); } catch (Exception ex) { WriteLog(ex); return(-1); } }
/// <summary> /// Change status home /// </summary> /// <param name="pId"></param> /// <param name="status"></param> /// <returns></returns> public int ChangeIsHome(int pId, int status) { try { db = new THN_WebApplicationEntities(); var product = db.Products.Find(pId); if (product == null || product.ID <= 0) { return(0); } product.IsHome = status == 1 ? true : false; if (db.SaveChanges() > 0) { return(1); } return(0); } catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(-1); } }
/// <summary> /// Change display /// </summary> /// <param name="pId"></param> /// <param name="visibled"></param> /// <returns></returns> public int ChangeVisibled(int pId, int visibled) { try { db = new THN_WebApplicationEntities(); var product = db.Products.Find(pId); if (product == null || product.ID <= 0) { return(0); } product.Visibled = visibled; if (db.SaveChanges() > 0) { return(1); } return(0); } catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(-1); } }
/// <summary> /// Insert new User /// </summary> /// <param name="add"></param> /// <returns></returns> public int Insert(User add) { //1 : true; 0: false; -1: Exception; 2: Đã tồn tại try { db = new THN_WebApplicationEntities(); var check = db.Users.Where(u => u.Username == add.Username || u.Email == add.Email).ToList(); if (check.Count > 0) { return(2); } db.Users.Add(add); if (db.SaveChanges() > 0) { return(1); } return(0); } catch (Exception ex) { WriteLog(ex); return(-1); } }
/// <summary> /// Delete a Product /// </summary> /// <param name="id"></param> /// <returns></returns> public int Delete(int id) { try { db = new THN_WebApplicationEntities(); var produdct = db.Products.Find(id); if (produdct == null || produdct.ID <= 0) { return(0); } var lstImages = db.ProductImages.Where(p => p.ProductID == produdct.ID).ToList(); if (lstImages.Count > 0) { string folder = "P" + id; db.ProductImages.RemoveRange(lstImages); foreach (var img in lstImages) { string path = "~/Images/product/" + folder + "/" + img.FileSave; FileHelper.delete(path); } } db.Products.Remove(produdct); if (db.SaveChanges() > 0) { FileHelper.delete("~/Images/product/thump/" + produdct.Picture); return(1); } return(0); } catch (Exception ex) { WriteLogs.WriteToLogFile(ex); return(-1); } }