public ViewModel.ReturnResult <bool> UpdateProjectFeature(ViewModel.ProjectFeatureModel projectFeature) { var returnResult = new ViewModel.ReturnResult <bool>(); try { var context = new DomainDeriven.AkoSatrapDb(); var dbProjectFeature = context.ProjectFeatures.Include("ProjectFeature2") .FirstOrDefault(r => !r.IsEnglish.Value && r.Id == projectFeature.Id); if (dbProjectFeature != null) { dbProjectFeature.Title = projectFeature.Title; dbProjectFeature.ProjectFeature2.Title = projectFeature.EnTitle; dbProjectFeature.Description = projectFeature.Description; dbProjectFeature.ProjectFeature2.Description = projectFeature.EnDescription; dbProjectFeature.Order = projectFeature.Order; dbProjectFeature.ProjectFeature2.Order = projectFeature.Order; context.SaveChanges(); } else { returnResult.SetError("جزییات محصول مورد نظر پیدا نشد"); } context.SaveChanges(); } catch (Exception ex) { returnResult.SetError(ex.Message); } return(returnResult); }
public ViewModel.ReturnResult <bool> AddProjectDetail(ViewModel.ProjectFeatureModel projectFeature) { var returnResult = new ViewModel.ReturnResult <bool>(); try { var context = new DomainDeriven.AkoSatrapDb(); var project = context.Projects.Include("Project2").FirstOrDefault(r => r.Id == projectFeature.ProjectId); if (project != null) { var enProductFeatureDb = new DomainDeriven.ProjectFeature { Title = projectFeature.EnTitle, Description = projectFeature.EnDescription, Order = projectFeature.Order, ProjectId = project.Project2.Id, IsEnglish = true }; var faProjectFeatureDb = new DomainDeriven.ProjectFeature { Title = projectFeature.Title, Description = projectFeature.Description, Order = projectFeature.Order, ProjectFeature2 = enProductFeatureDb, ProjectId = project.Id, IsEnglish = false }; context.ProjectFeatures.Add(faProjectFeatureDb); context.SaveChanges(); } else { returnResult.SetError("محصول مورد نظر پیدا نشدُ"); } } catch (Exception ex) { returnResult.SetError(ex.Message); } return(returnResult); }