public virtual void Update(TModel model) { using (UnitOfWork <TDbContext, TUser> unitOfWork = new UnitOfWork <TDbContext, TUser>()) { var dbmodel = unitOfWork.GenericRepository.Get <TModel>(f => f.Id == model.Id, includeProperties: Includes).FirstOrDefault(); Guard.AgainstNull <NotFoundException>(dbmodel, ModelNameSingular.ToString()); // ReSharper disable once PossibleNullReferenceException Guard.AgainstFalse <PermissionException>(dbmodel.IsUserCanModify(), ModelNameSingular.ToString()); dbmodel.Update(model); unitOfWork.Commit(); } }
public virtual TModel GetById(int id) { Guard.AgainstFalse <ArgumentException>(id > 0, ModelNameSingular?.ToString()); var model = Search(new SearchCriteria <TModel>() { FilterExpression = a => a.Id == id }).Result.FirstOrDefault(); Guard.AgainstNull <NotFoundException>(model, ModelNameSingular?.ToString()); Guard.AgainstFalse(model.IsUserCanView()); return(model); }
public virtual void Delete(int id) { using (UnitOfWork <TDbContext, TUser> unitOfWork = new UnitOfWork <TDbContext, TUser>()) { var forum = unitOfWork.GenericRepository.Get <TModel>(f => f.Id == id, includeProperties: Includes).FirstOrDefault(); Guard.AgainstNull <NotFoundException>(forum, ModelNameSingular.ToString()); // ReSharper disable once PossibleNullReferenceException Guard.AgainstFalse <PermissionException>(forum.IsUserCanModify(CrudOperationType.Delete), ModelNameSingular.ToString()); unitOfWork.GenericRepository.Delete(forum); unitOfWork.Commit(); } }