public bool DeleteCategory(int OutletId) { try { DataLayer.Entities.Category category = _categoryRepo.Get(OutletId); category.Status = CommonConstants.StatusTypes.Archived; _categoryRepo.Update(category); return(true); } catch (Exception ex) { _categoryRepo.Rollback(); int pk = _crashLogRepo.AsQueryable().Count() + 1; _crashLogRepo.Add(new DataLayer.Entities.Crashlog { CrashLogId = pk, ClassName = "CategoryService", MethodName = "DeleteCategory", ErrorMessage = ex.Message.ToString(), ErrorInner = (string.IsNullOrEmpty(ex.Message) || ex.Message == CommonConstants.MsgInInnerException ? ex.InnerException.Message : ex.Message).ToString(), Data = OutletId.ToString(), TimeStamp = DateTime.Now }); return(false); } }
public HttpResponseMessage Delete(DeleteDTO dto) { var cat = _repository.Get(dto.categoryId, ActiveModule.ModuleID); _repository.Delete(cat); return(Request.CreateResponse(System.Net.HttpStatusCode.NoContent)); }
// GET: Categories/Details/5 public ActionResult Details(int id) { Category category = categoryRepo.Get(id); if (category == null) { return(HttpNotFound()); } return(View(category)); }
/// <summary> /// 映射Dto /// </summary> /// <typeparam name="T"></typeparam> /// <param name="statement"></param> /// <returns></returns> private T MapToDto <T>(StatementEntity statement) where T : MapDto { T dto = Mapper.Map <T>(statement); if (statement.CategoryId != null) { var category = _categoryRepo.Get(statement.CategoryId.Value) ?? throw new KnownException("账单分类数据查询失败!", ServiceResultCode.NotFound); dto.CategoryName = category.Name; dto.CategoryIconPath = _fileRepo.GetFileUrl(category.IconUrl); } else { if (statement.Type.Equals(StatementTypeEnum.transfer.ToString())) { dto.CategoryIconPath = _fileRepo.GetFileUrl("core/images/category/icon_transfer_64.png"); } else if (statement.Type.Equals(StatementTypeEnum.repayment.ToString())) { dto.CategoryIconPath = _fileRepo.GetFileUrl("core/images/category/icon_repayment_64.png"); } } var asset = _assetRepo.Get(statement.AssetId) ?? throw new KnownException("资产分类数据查询失败!", ServiceResultCode.NotFound); if (statement.TargetAssetId != null) { var targetAsset = _assetRepo.Get(statement.TargetAssetId.Value); dto.TargetAssetName = targetAsset.Name; } dto.AssetName = asset.Name; dto.TypeName = Switcher.StatementType(statement.Type); return(dto); }
// GET: Products/Details/5 public ActionResult Details(int id) { Product product = productRepo.Get(id); product.Category = categoryRepo.Get(product.Id); if (product == null) { return(HttpNotFound()); } return(View(product)); }
public IHttpActionResult Get(int id) { var category = _categoryRepo.Get(id); if (category != null) { return(Ok(Map <CategoryViewModel>(category))); } else { return(NotFound()); } }
public ActionResult List(string name = null) { User user = GetCurrentUser(); if (user == null) { return(RedirectToAction("Login", "Account")); } ICategoryRepo repo = UnitOfWork.CategoryRepo; return(View(repo.Get().Select(c => new GetCategoryListViewModel { Id = c.Id, Name = c.Name }))); }
public async Task <PagedDto <CategoryPageDto> > GetPageAsync(CategoryPagingDto pagingDto) { if (pagingDto.CreateStartTime != null && pagingDto.CreateEndTime == null) { throw new KnownException("创建时间参数有误", ServiceResultCode.ParameterError); } var parentIds = new List <string>(); if (!string.IsNullOrWhiteSpace(pagingDto.ParentIds)) { parentIds = pagingDto.ParentIds.Split(",").ToList(); } pagingDto.Sort = pagingDto.Sort.IsNullOrEmpty() ? "id ASC" : pagingDto.Sort.Replace("-", " "); var categories = await _categoryRepo .Select .WhereIf(!string.IsNullOrWhiteSpace(pagingDto.CategoryName), c => c.Name.Contains(pagingDto.CategoryName)) .WhereIf(parentIds != null && parentIds.Any(), c => parentIds.Contains(c.ParentId.ToString())) .WhereIf(!string.IsNullOrWhiteSpace(pagingDto.Type), c => c.Type.Equals(pagingDto.Type)) .WhereIf(pagingDto.CreateStartTime != null, c => c.CreateTime >= pagingDto.CreateStartTime && c.CreateTime <= pagingDto.CreateEndTime) .OrderBy(pagingDto.Sort) .ToPageListAsync(pagingDto, out long totalCount); var categoryDtos = categories.Select(c => { var dto = Mapper.Map <CategoryPageDto>(c); CategoryEntity category = null; if (c.ParentId != 0) { category = _categoryRepo.Get(c.ParentId); } dto.ParentName = category?.Name; dto.TypeName = SystemConst.Switcher.CategoryType(c.Type); dto.IconUrl = _fileRepo.GetFileUrl(c.IconUrl); return(dto); }).ToList(); return(new PagedDto <CategoryPageDto>(categoryDtos, totalCount)); }
public Category GetCategory(Expression <Func <Category, bool> > expression) { return(categoryRepo.Get(expression)); }
public IActionResult GetAllCategories() { var categories = _categoryRepo.Get(); return(Ok(categories)); }