/// <summary> /// This method is used for insert new category in database. - JJ /// </summary> /// <param name="category">object of CategoryAC</param> /// <param name="companyId"></param> /// <returns>saved object of CategoryAC</returns> public CategoryAC SaveCategory(CategoryAC category, int companyId) { try { var categorys = new Category { CompanyId = companyId, GroupParamTypeId = category.GroupParamTypeId, BrandParamTypeId = category.BrandParamTypeId, CreatedDateTime = DateTime.UtcNow, }; _categoryContext.Add(categorys); _categoryContext.SaveChanges(); category.CategoryId = categorys.Id; var supplier = new ItemSupplier { SupplierId = category.SupplierId, CategoryId = category.CategoryId, CreatedDateTime = DateTime.UtcNow }; _itemSupplierContext.Add(supplier); _itemSupplierContext.SaveChanges(); return(category); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
/// <summary> /// check category exists in databse or not. - JJ /// </summary> /// <param name="category"></param> /// <param name="companyId"></param> /// <returns>return true if category already exist,otherwise false</returns> public bool CheckCategoryExixtsOrNot(CategoryAC category, int companyId) { try { return(_categoryContext.Fetch(x => x.GroupParamTypeId == category.GroupParamTypeId && x.BrandParamTypeId == category.BrandParamTypeId && x.Id != category.CategoryId && x.IsDelete == false && x.CompanyId == companyId).Any()); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }
public IHttpActionResult SaveCategory(CategoryAC category) { try { bool isCategoryExist = _categoryContext.CheckCategoryExixtsOrNot(category, companyId); if (isCategoryExist) { return(Ok(new { isCategoryExist = isCategoryExist })); } var categorys = _categoryContext.SaveCategory(category, companyId); return(Ok(categorys)); } catch (Exception ex) { _errorLog.LogException(ex); throw; } }