public ViewModel.ReturnResult <bool> UpdateProductCategory(ViewModel.ProductCategotyModel productCategory) { ViewModel.ReturnResult <bool> returnResult = new ViewModel.ReturnResult <bool>(); try { DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb(); var dbProductCategory = context.ProductCategories.Include("ProductCategory2").FirstOrDefault(r => r.IsEnglish == false && r.Id == productCategory.Id); if (dbProductCategory != null) { dbProductCategory.Title = productCategory.Title; dbProductCategory.ProductCategory2.Title = productCategory.EnTitle; context.SaveChanges(); } else { returnResult.SetError("دسته بندی مورد نظر پیدا نشد"); } context.SaveChanges(); } catch (Exception ex) { returnResult.SetError(ex.Message); } return(returnResult); }
public ViewModel.ReturnResult <bool> AddProductCategory(ViewModel.ProductCategotyModel productCategory) { ViewModel.ReturnResult <bool> returnResult = new ViewModel.ReturnResult <bool>(); try { DomainDeriven.AkoSatrapDb context = new DomainDeriven.AkoSatrapDb(); var enDbProductCategory = new DomainDeriven.ProductCategory(); var dbProductCategory = new DomainDeriven.ProductCategory(); enDbProductCategory.Title = productCategory.EnTitle; enDbProductCategory.IsEnglish = true; dbProductCategory.Title = productCategory.Title; dbProductCategory.IsEnglish = false; dbProductCategory.ProductCategory2 = enDbProductCategory; context.ProductCategories.Add(dbProductCategory); context.SaveChanges(); } catch (Exception ex) { returnResult.SetError(ex.Message); } return(returnResult); }