コード例 #1
0
ファイル: Entity.cs プロジェクト: DavidManya/ASP.NET-Empleats
        public virtual DeleteValidation <T> Delete <T>() where T : Entity
        {
            var output = new DeleteValidation <T>();

            CurrentValidation = Validate();

            if (CurrentValidation.IsSuccess)
            {
                var repo = DepCon.Resolve <IRepository <T> >();

                output = repo.Delete(this as T);
            }

            output.Validation = CurrentValidation;

            return(output);
        }
コード例 #2
0
        public virtual DeleteValidation <T> Delete(T entity)
        {
            var output = new DeleteValidation <T>()
            {
                DeleteValidationSuccesful = true
            };

            if (DbSet.All(x => x.Id != entity.Id))
            {
                output.DeleteValidationSuccesful = false;
                output.Validation.Messages.Add("No existe una entity con ese id");
            }

            if (output.DeleteValidationSuccesful)
            {
                DbSet.Remove(entity);
            }

            return(output);
        }
コード例 #3
0
        public virtual DeleteValidation <T> Delete(T entity)
        {
            var output = new DeleteValidation <T>()
            {
                IsSuccess = true
            };

            if (DbSet.All(x => x.Id != entity.Id))
            {
                output.IsSuccess = false;
                output.Validation.Errors.Add("No existe una entity con ese id");
            }

            if (output.IsSuccess)
            {
                DbSet.Remove(entity);
                DbContext.SaveChanges();
            }

            return(output);
        }