public void AddArticle(Article article) { var user = GetCurrentUser(); article.InsertDate = DateTime.Now; article.InsertUser = user.UserName; article.AddedDate = DateTime.Now; article.UserId = user.Id; _context.Articles.Add(article); _context.SaveChanges(); _logger.LogEvent(article.GetType().Name, article.Id, "Add"); }
public ProductMainFeature AddProductMainFeature(ProductMainFeature mainFeature) { var user = GetCurrentUser(); mainFeature.InsertDate = DateTime.Now; mainFeature.InsertUser = user.UserName; _context.ProductMainFeatures.Add(mainFeature); _context.SaveChanges(); _logger.LogEvent(mainFeature.GetType().Name, mainFeature.Id, "Add"); return(mainFeature); }
public ProductGroup AddNewProductGroup(int parentId, string title, List <int> brandIds, List <int> featureIds) { var productGroup = new ProductGroup(); var user = GetCurrentUser(); productGroup.InsertDate = DateTime.Now; productGroup.InsertUser = user.UserName; #region Adding Product Group productGroup.Title = title; if (parentId != 0) { productGroup.ParentId = parentId; } _context.ProductGroups.Add(productGroup); _context.SaveChanges(); _logger.LogEvent(productGroup.GetType().Name, productGroup.Id, "Add"); #endregion #region Adding Product Group Brands foreach (var brandId in brandIds) { var productGroupBrand = new ProductGroupBrand(); productGroupBrand.ProductGroupId = productGroup.Id; productGroupBrand.BrandId = brandId; _context.ProductGroupBrands.Add(productGroupBrand); } _context.SaveChanges(); #endregion #region Adding product Group Features foreach (var featureId in featureIds) { var productGroupFeature = new ProductGroupFeature(); productGroupFeature.ProductGroupId = productGroup.Id; productGroupFeature.FeatureId = featureId; _context.ProductGroupFeatures.Add(productGroupFeature); } _context.SaveChanges(); #endregion return(productGroup); }
public ArticleComment DeleteComment(int id) { var comment = _context.ArticleComments.Find(id); var children = _context.ArticleComments.Where(c => c.ParentId == id).ToList(); foreach (var child in children) { child.IsDeleted = true; _context.Entry(child).State = EntityState.Modified; _context.SaveChanges(); } comment.IsDeleted = true; _context.Entry(comment).State = EntityState.Modified; _context.SaveChanges(); _logger.LogEvent(comment.GetType().Name, comment.Id, "Delete"); return(comment); }