public void UpdateTopHot(string CategoryGuid, bool TopHot) { shCategoryService _category = new shCategoryService(); shCategory category = _category.FindByKey(CategoryGuid); if (category != null) { category.TopHot = TopHot; _category.Update(category); } }
public shCategory ThemMoi_HieuChinhCategory(string CategoryGuid, int?CategoryId, string CategoryName, string ParentId, int?UserId, bool?Status, DateTime?CreatedDate, string MetaTitle, string Description, int?SortOrder, string FileName) { shCategoryService _category = new shCategoryService(); shCategory category = new shCategory(); if (!string.IsNullOrWhiteSpace(CategoryGuid)) { category = _category.FindByKey(CategoryGuid); } else { CategoryGuid = GuidUnique.getInstance().GenerateUnique(); } try { // Your code... // Could also be before try if you know the exception occurs in SaveChanges category.CategoryGuid = CategoryGuid; category.CategoryName = CategoryName; category.ParentId = ParentId; category.UserId = UserId; category.Status = Status; category.CreatedDate = CreatedDate; category.Description = Description; category.SortOrder = SortOrder; if (string.IsNullOrWhiteSpace(ParentId) || string.IsNullOrEmpty(ParentId)) { category.MetaTitle = "/" + StringHelper.ToUnsignString(CategoryName).ToLower() + "/" + StringHelper.ToUnsignString(Description.Substring(0, 60)).ToLower(); } else { category.MetaTitle = TaoLinkUrl(CategoryGuid, CategoryName); } category.FileName = FileName; if (category.CategoryId > 0) { _category.Update(category); } else { _category.Insert(category); } return(category); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return(category); } }