public void SetRelation(IClassifiable relatable, IClassifiable related, RelationDirection direction = RelationDirection.Undefined, TaxonomyNode type = null) { foreach (var relEntity in relationRepo.GetRelated(relatable, direction, type == null ? null : type.entity)) { relationRepo.Delete(relEntity); } RelateInternal(relatable, related, direction, type); }
public void Can_Perform_Delete_On_RelationRepository() { // Arrange using (IScope scope = ScopeProvider.CreateScope()) { RelationRepository repository = CreateRepository(ScopeProvider, out RelationTypeRepository repositoryType); // Act IRelation relation = repository.Get(2); repository.Delete(relation); bool exists = repository.Exists(2); // Assert Assert.That(exists, Is.False); } }
public void Can_Perform_Delete_On_RelationRepository() { // Arrange var provider = new PetaPocoUnitOfWorkProvider(); var unitOfWork = provider.GetUnitOfWork(); var repositoryType = new RelationTypeRepository(unitOfWork); var repository = new RelationRepository(unitOfWork, NullCacheProvider.Current, repositoryType); // Act var relation = repository.Get(2); repository.Delete(relation); unitOfWork.Commit(); var exists = repository.Exists(2); // Assert Assert.That(exists, Is.False); }
public ActionResult UploadUserImage() { try { if (Request.ContentLength < 70) { return(Json(new JsonData() { Success = true, Script = MessageBox.Show("عملیات درج با موفقیت انجام شد", MessageType.Success).Script, Html = "" })); } else { long userId = Convert.ToInt64(Session["User_Id_Boss"]); long relationId = Convert.ToInt64(Session["Relation_Id_Boss"]); var user = blUser.Find(userId); user.ConfirmPassword = user.Password; var UploadImage = Request.Files[0]; string imagePath = null; string fileName = UploadImage.FileName; if (!fileName.IsImage()) { string message = ""; blUser.Delete(userId, out message); string message2 = ""; blRelation.Delete(relationId, out message2); return(Json(new JsonData() { Success = false, Script = MessageBox.Show("فایل تصویر معتبر نیست", MessageType.Error).Script, Html = "" })); } // وقتی عکسی وجود داشت نام عکس جدید را تغییر دهد while (System.IO.File.Exists(Server.MapPath("~") + "Files\\UploadImages\\" + fileName) == true) { string extension = fileName.Substring(fileName.Length - 4); fileName = fileName.Replace(extension, ""); fileName += 1.ToString(); fileName = fileName + extension; } // user.Image = fileName; imagePath = Server.MapPath("~") + "Files\\UploadImages\\" + fileName; UploadImage.InputStream.ResizeImageByWidth(500, imagePath, Utilities.ImageComperssion.Normal); string message3 = ""; if (blUser.Update(user, fileName, null, out message3)) { return(Json(new JsonData() { Success = true, Script = MessageBox.Show("عملیات درج با موفقیت انجام شد", MessageType.Success).Script, Html = "" })); } else { string message = ""; blUser.Delete(user, out message); if (user.Image != null) { if (System.IO.File.Exists(Server.MapPath("~") + "Files\\UploadImages\\" + user.Image)) { System.IO.File.Delete(Server.MapPath("~") + "Files\\UploadImages\\" + user.Image); } } return(Json(new JsonData() { Success = false, Script = MessageBox.Show("فایل تصویر آپلود نشده است", MessageType.Error).Script, Html = "" })); } } } catch { string message = ""; blUser.Delete(Convert.ToInt64(Session["User_Id_Boss"]), out message); string message2 = ""; blRelation.Delete(Convert.ToInt64(Session["Relation_Id_Boss"]), out message2); return(Json(new JsonData() { Success = false, Script = MessageBox.Show("در آپلود تصویر مشکل پیش آمده است. مجددا تلاش کنید", MessageType.Error).Script, Html = "" })); } }
public MyHourMutation(UserRepository userRepository, RelationRepository relationRepository, ProjectRepository projectRepository) { Field <RelationType>("createRelation", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <RelationInputType> > { Name = "input" }), resolve: context => relationRepository.Create(context.GetArgument <Relation>("input")) ); Field <RelationType>("deleteRelation", arguments: new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }), resolve: context => relationRepository.Delete(context.GetArgument <long>("id")) ); Field <RelationType>("updateRelation", arguments: new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }, new QueryArgument <NonNullGraphType <RelationInputType> > { Name = "input" }), resolve: context => relationRepository.Update(context.GetArgument <long>("id"), context.GetArgument <Relation>("input")) ); Field <RelationType>("updateRelationTime", arguments: new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }, new QueryArgument <NonNullGraphType <RelationInputType> > { Name = "input" }), resolve: context => relationRepository.UpdateTime(context.GetArgument <long>("id"), context.GetArgument <Relation>("input")) ); Field <ProjectType>("createProject", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <ProjectInputType> > { Name = "input" }), resolve: context => projectRepository.Create(context.GetArgument <Project>("input")) ); Field <ProjectType>("deleteProject", arguments: new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }), resolve: context => projectRepository.Delete(context.GetArgument <long>("id")) ); Field <ProjectType>("updateProject", arguments: new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }, new QueryArgument <NonNullGraphType <ProjectInputType> > { Name = "input" }), resolve: context => projectRepository.Update(context.GetArgument <long>("id"), context.GetArgument <Project>("input")) ); Field <UserType>("createUser", arguments: new QueryArguments(new QueryArgument <NonNullGraphType <UserInputType> > { Name = "input" }), resolve: context => userRepository.Create(context.GetArgument <User>("input")) ); Field <UserType>("deleteUser", arguments: new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }), resolve: context => userRepository.Delete(context.GetArgument <long>("id")) ); Field <UserType>("updateUser", arguments: new QueryArguments(new QueryArgument <IdGraphType> { Name = "id" }, new QueryArgument <NonNullGraphType <UserInputType> > { Name = "input" }), resolve: context => userRepository.Update(context.GetArgument <long>("id"), context.GetArgument <User>("input")) ); }