public async Task <ActionResult <IEnumerable <object> > > GetWarehouses([FromQuery] PaginationParametersModel pagingParameters) { IQueryable <WarehouseObjectModel> Warehouses = _context.Warehouses.AsQueryable(); pagingParameters.Init(await _context.Warehouses.CountAsync()); Warehouses = Warehouses.OrderBy(x => x.Id); if (pagingParameters.PageNum > 1) { Warehouses = Warehouses.Skip(pagingParameters.Skip); } HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос складов хранения обработан", Status = StylesMessageEnum.success.ToString(), Tag = await Warehouses.Take(pagingParameters.PageSize).Select(warehouse => new { warehouse.Id, warehouse.Name, warehouse.Information, warehouse.isReadonly, warehouse.isDisabled, warehouse.isGlobalFavorite }).ToArrayAsync() })); }
public async Task <ActionResult <IEnumerable <object> > > GetTelegramBotUpdate([FromQuery] PaginationParametersModel pagingParameters) { pagingParameters.Init(await _context.TelegramBotUpdates.CountAsync()); IQueryable <TelegramBotUpdateObjectModel> botUpdates = _context.TelegramBotUpdates.OrderBy(x => x.Id); if (pagingParameters.PageNum > 1) { botUpdates = botUpdates.Skip(pagingParameters.Skip); } HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос TelegramBot Updates", Status = StylesMessageEnum.success.ToString(), Tag = await botUpdates.Include(x => x.User).Take(pagingParameters.PageSize).Select(x => new { x.Id, x.Name, x.Information, x.DateCreate, x.isBotMessage, User = new { x.User.Id, x.User.Name, Role = x.User.Role.ToString() } }).ToListAsync() })); }
public async Task <ActionResult <IEnumerable <object> > > GetBtcTransactions([FromQuery] PaginationParametersModel pagingParameters) { pagingParameters.Init(await _context.BtcTransactions.CountAsync()); IQueryable <BtcTransactionObjectModel> users = _context.BtcTransactions.OrderBy(x => x.Id); if (pagingParameters.PageNum > 1) { users = users.Skip(pagingParameters.Skip); } HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос Electrum/BTC транзакций обработан", Status = StylesMessageEnum.success.ToString(), Tag = (await _context.BtcTransactions.ToListAsync()).Select(tx => new { tx.Id, tx.Name, tx.Information, tx.Sum, tx.TxId, CountOutputs = _context.BtcTransactionOuts.Count(txOut => txOut.BtcTransactionId == tx.Id) }) })); }
public async Task <ActionResult <object> > GetWarehouse([FromQuery] PaginationParametersModel pagingParameters, [FromRoute] int id) { WarehouseObjectModel warehouse = await _context.Warehouses.Include(x => x.Avatar).FirstOrDefaultAsync(x => x.Id == id); if (warehouse == null) { _logger.LogError("Склад не найден: id={0}", id); return(new ObjectResult(new ServerActionResult() { Success = false, Info = "Склад не найден", Status = StylesMessageEnum.danger.ToString() })); } IQueryable <WarehouseDocumentsModel> wDocuments = _context.WarehouseDocuments .Where(wDoc => wDoc.WarehouseReceiptId == id || (wDoc.Discriminator == nameof(InternalDisplacementWarehouseDocumentModel) && ((InternalDisplacementWarehouseDocumentModel)wDoc).WarehouseDebitingId == id)).OrderBy(x => x.Id); pagingParameters.Init(await wDocuments.CountAsync()); if (pagingParameters.PageNum > 1) { wDocuments = wDocuments.Skip(pagingParameters.Skip); } wDocuments = wDocuments.Take(pagingParameters.PageSize) .Include(wDoc => wDoc.Author) .Include(wDoc => wDoc.WarehouseReceipt); HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос номенклатуры обработан", Status = StylesMessageEnum.success.ToString(), Tag = new { warehouse.Id, warehouse.Name, warehouse.Information, warehouse.isDisabled, warehouse.isGlobalFavorite, warehouse.isReadonly, Documents = (await wDocuments.ToListAsync()).Select(wDoc => BodyGoodMovementDocumentModel.getDocument(wDoc, _context)), Avatar = new { warehouse.Avatar?.Id, warehouse.Avatar?.Name }, noDelete = _context.WarehouseDocuments.Any(wDoc => wDoc.WarehouseReceiptId == id) || _context.InternalDisplacementWarehouseDocuments.Any(dwDoc => dwDoc.WarehouseDebitingId == id) || _context.InventoryGoodsBalancesWarehouses.Any(x => x.WarehouseId == id) } })); }
public async Task <ActionResult <IEnumerable <object> > > GetDepartments([FromQuery] PaginationParametersModel pagingParameters) { IQueryable <DepartmentObjectModel> departments = _context.Departments.AsQueryable(); if (_user.Role < AccessLevelUserRolesEnum.Admin) { departments = departments.Where(x => !x.isDisabled); } pagingParameters.Init(await departments.CountAsync()); departments = departments.OrderBy(x => x.Id); if (pagingParameters.PageNum > 1) { departments = departments.Skip(pagingParameters.Skip); } HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); departments = departments.Take(pagingParameters.PageSize); string TypeName = nameof(DepartmentObjectModel); var qDepartments = from department in departments join UserFavoriteLocator in _context.UserFavoriteLocators on new { ObjectId = department.Id, TypeName, UserId = _user.Id } equals new { UserFavoriteLocator.ObjectId, UserFavoriteLocator.TypeName, UserFavoriteLocator.UserId } into joinFavoriteLocator from isFavoriteMark in joinFavoriteLocator.DefaultIfEmpty() select new { department, isFavoriteMark }; return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос дапартаментов обработан", Status = StylesMessageEnum.success.ToString(), Tag = (await qDepartments.ToListAsync()).Select(selectItem => new { selectItem.department.Id, selectItem.department.Name, selectItem.department.Information, selectItem.department.isDisabled, selectItem.department.isGlobalFavorite, IsUserFavorite = selectItem.isFavoriteMark != null, selectItem.department.isReadonly, Avatar = new { selectItem.department.Avatar?.Id, selectItem.department.Avatar?.Name } }) })); }
public ActionResult <IEnumerable <object> > Ftp(PaginationParametersModel pagingParameters) { List <FileInfo> Files = new DirectoryInfo(conf.UploadsPath).GetFiles().Where(x => x.Name.Substring(0, 1) != ".").OrderBy(c => c.Name).ToList(); pagingParameters.Init(ref Files); HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Доступ к начальной папке успешно обработан", Status = StylesMessageEnum.success.ToString(), Tag = Files.Select(x => new { x.Name, Size = glob_tools.SizeDataAsString(x.Length) }).ToArray() })); }
public async Task <ActionResult <IEnumerable <object> > > GetWarehouseDocuments([FromQuery] PaginationParametersModel pagingParameters) { IQueryable <WarehouseDocumentsModel> documents = _context.WarehouseDocuments.Where(x => x.Discriminator.ToLower() != nameof(WarehouseDocumentsModel).ToLower()).AsQueryable(); pagingParameters.Init(await documents.CountAsync()); HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); documents = documents.OrderByDescending(doc => doc.Id); if (pagingParameters.PageNum > 1) { documents = documents.Skip(pagingParameters.Skip); } documents = documents .Take(pagingParameters.PageSize) .Include(doc => doc.Author) .Include(doc => doc.WarehouseReceipt); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос складских документов обработан", Status = StylesMessageEnum.success.ToString(), Tag = await documents.Select(doc => new { doc.Id, doc.DateCreate, doc.Name, doc.Information, Author = new { doc.Author.Id, doc.Author.Name }, WarehouseReceipt = new { doc.WarehouseReceipt.Id, doc.WarehouseReceipt.Name, doc.WarehouseReceipt.Information }, CountRows = _context.GoodMovementDocumentRows.Count(row => row.BodyDocumentId == doc.Id), doc.Discriminator }).ToListAsync() })); }
public async Task <ActionResult <object> > GetGroupsGoods([FromQuery] PaginationParametersModel pagingParameters) { IQueryable <GroupGoodsObjectModel> groups = _context.GroupsGoods.AsQueryable(); if (_user.Role < AccessLevelUserRolesEnum.Admin) { groups = groups.Where(group => !group.isDisabled); } pagingParameters.Init(await _context.GroupsGoods.CountAsync()); groups = groups.OrderBy(x => x.Id); if (pagingParameters.PageNum > 1) { groups = groups.Skip(pagingParameters.Skip); } groups = groups.Take(pagingParameters.PageSize); HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос групп номенклатуры обработан", Status = StylesMessageEnum.success.ToString(), Tag = await groups.Include(x => x.Avatar).Select(group => new { group.Id, group.Name, group.Information, group.isReadonly, group.isDisabled, group.isGlobalFavorite, Avatar = new { group.Avatar.Id, group.Avatar.Name, group.Avatar.Information }, countGoods = _context.Goods.Count(good => good.GroupId == group.Id) }).ToListAsync() })); }
public async Task <ActionResult <IEnumerable <object> > > GetDeliveryMethods([FromQuery] PaginationParametersModel pagingParameters) { pagingParameters.Init(await _context.DeliveryServices.CountAsync()); IQueryable <DeliveryServiceObjectModel> delServices = _context.DeliveryServices.OrderBy(x => x.Id); if (pagingParameters.PageNum > 1) { delServices = delServices.Skip(pagingParameters.Skip); } HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос дапартаментов обработан", Status = StylesMessageEnum.success.ToString(), Tag = await delServices.Take(pagingParameters.PageSize).ToListAsync() })); }
public ActionResult <IEnumerable <object> > Storage(PaginationParametersModel pagingParameters) { IQueryable <FileStorageObjectModel> files = DbContext.FilesStorage.Include(x => x.LogAccessorRow).Where(x => x.LogAccessorRow == null).OrderBy(x => x.Id); pagingParameters.Init(files.Count()); if (pagingParameters.PageNum > 1) { files = files.Skip(pagingParameters.Skip); } HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); //List<FileStorageModel> filesList = files.Take(pagingParameters.PageSize).ToList(); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Доступ к хранимой папке успешно обработан", Status = StylesMessageEnum.success.ToString(), Tag = files.Take(pagingParameters.PageSize).ToList().Where(x => System.IO.File.Exists(Path.Combine(StoragePath, x.Id.ToString() + Path.GetExtension(x.Name)))).Select(x => new { x.Id, x.Name, Size = glob_tools.SizeDataAsString(x.Length), x.isDisabled, x.isReadonly }).ToArray() })); }
public async Task <ActionResult <IEnumerable <object> > > GetNotification([FromQuery] PaginationParametersModel pagingParameters) { IQueryable <NotificationObjectModel> notifications = _context.Notifications.Where(x => x.RecipientId == _user.Id); pagingParameters.Init(await notifications.CountAsync()); if (pagingParameters.PageNum > 1) { notifications = notifications.Skip(pagingParameters.Skip); } HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); notifications = notifications.OrderBy(x => x.DateCreate).Include(x => x.Conversation); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос уведомлений обработан", Status = StylesMessageEnum.success.ToString(), Tag = (await notifications.ToListAsync()).Select(x => new { x.Id, x.Name, x.Information, x.DateCreate, Conversation = new { x.Conversation.Id, x.Conversation.Name, x.Conversation.Information, Initiator = new { Id = x.Conversation.InitiatorId, Type = x.Conversation.InitiatorType.ToString() }, x.Conversation.DateCreate }, DeliveryStatus = x.DeliveryStatus.ToString() }) })); }
public async Task <ActionResult <IEnumerable <object> > > GetUnits([FromQuery] PaginationParametersModel pagingParameters) { IQueryable <UnitGoodObjectModel> units = _context.Units.AsQueryable(); pagingParameters.Init(await units.CountAsync()); units = _context.Units.OrderBy(x => x.Id); if (pagingParameters.PageNum > 1) { units = units.Skip(pagingParameters.Skip); } string TypeName = nameof(UnitGoodObjectModel); var qUnits = from unit in units join UserFavoriteLocator in _context.UserFavoriteLocators on new { ObjectId = unit.Id, TypeName, UserId = _user.Id } equals new { UserFavoriteLocator.ObjectId, UserFavoriteLocator.TypeName, UserFavoriteLocator.UserId } into joinFavoriteLocator from isFavoriteMark in joinFavoriteLocator.DefaultIfEmpty() select new { unit, isFavoriteMark }; HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос групп номенклатуры обработан", Status = StylesMessageEnum.success.ToString(), Tag = await qUnits.Take(pagingParameters.PageSize).Select(selectItem => new { selectItem.unit.Id, selectItem.unit.Name, selectItem.unit.Information, isUserFavorite = selectItem.isFavoriteMark != null }).ToListAsync() })); }
public async Task <ActionResult <object> > GetGood([FromQuery] PaginationParametersModel pagingParameters, int id) { GoodObjectModel good = await _context.Goods .Where(x => x.Id == id) .Include(x => x.Avatar) .Include(x => x.Unit) .Include(x => x.Group) .FirstOrDefaultAsync(); if (good == null) { _logger.LogError("Номенклатура не найдена: id={0}", id); return(new ObjectResult(new ServerActionResult() { Success = false, Info = "Номенклатура не найдена", Status = StylesMessageEnum.danger.ToString() })); } IQueryable <RowGoodMovementRegisterModel> goodRegisters = _context.GoodMovementDocumentRows.Where(x => x.GoodId == id); pagingParameters.Init(await goodRegisters.CountAsync()); goodRegisters = goodRegisters.OrderBy(x => x.Id); if (pagingParameters.PageNum > 1) { goodRegisters = goodRegisters.Skip(pagingParameters.Skip); } HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); goodRegisters = goodRegisters .Take(pagingParameters.PageSize) .Include(x => x.BodyDocument).ThenInclude(x => x.Author); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос номенклатуры обработан", Status = StylesMessageEnum.success.ToString(), Tag = new { good.Id, good.Name, good.Information, good.Price, good.GroupId, good.UnitId, good.isReadonly, good.isDisabled, good.isGlobalFavorite, noDelete = await _context.GoodMovementDocumentRows.AnyAsync(x => x.GoodId == id) || await _context.InventoryGoodsBalancesDeliveries.AnyAsync(x => x.GoodId == id) || await _context.InventoryGoodsBalancesWarehouses.AnyAsync(x => x.GoodId == id), Avatar = new { id = good.AvatarId, good.Avatar?.Name }, Units = await _context.Units.Select(x => new { x.Id, x.Name, x.Information }).ToListAsync(), Groups = await _context.GroupsGoods.Select(x => new { x.Id, x.Name, x.Information }).ToListAsync(), Registers = await goodRegisters .Select(x => new { x.Id, Document = BodyGoodMovementDocumentModel.getDocument(x.BodyDocument, _context), x.Quantity, x.UnitId }).ToListAsync() } })); }
public async Task <ActionResult <object> > GetGroupGoods([FromQuery] PaginationParametersModel pagingParameters, int id) { GroupGoodsObjectModel group = await _context.GroupsGoods.Include(group => group.Avatar).FirstOrDefaultAsync(group => group.Id == id); if (group is null) { _logger.LogError("Запрашиваемая группа товаров не найдена: id={0}", id); return(new ObjectResult(new ServerActionResult() { Success = false, Info = "Запрашиваемая группа товаров не найдена", Status = StylesMessageEnum.danger.ToString() })); } IQueryable <GoodObjectModel> goods = _context.Goods.Where(good => good.GroupId == id); pagingParameters.Init(await goods.CountAsync()); HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); goods = goods.OrderBy(good => good.Id); if (pagingParameters.PageNum > 1) { goods = goods.Skip(pagingParameters.Skip); } goods = goods.Take(pagingParameters.PageSize); return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос номенклатурнй группы обработан", Status = StylesMessageEnum.success.ToString(), Tag = new { group.Id, group.Name, group.Information, group.isDisabled, group.isGlobalFavorite, group.isReadonly, noDelete = await _context.Goods.AnyAsync(good => good.GroupId == id), Avatar = new { group.Avatar?.Id, group.Avatar?.Name, group.Avatar?.Information }, goods = await goods.Select(good => new { good.Id, good.Name, good.Information, good.Price, good.UnitId, good.isReadonly, good.isDisabled, good.isGlobalFavorite }).ToListAsync(), units = await _context.Units.Select(unit => new { unit.Id, unit.Name, unit.Information }).ToListAsync() } })); }
public async Task <ActionResult <object> > GetUnitGood([FromQuery] PaginationParametersModel pagingParameters, int id) { UnitGoodObjectModel unit = await _context.Units.FindAsync(id); if (unit == null) { _logger.LogError("Запрашиваемая единица измерения не найдена: id={0}", id); return(new ObjectResult(new ServerActionResult() { Success = false, Info = "Запрашиваемая единица измерения не найдена", Status = StylesMessageEnum.danger.ToString() })); } IQueryable <GoodObjectModel> goods = _context.Goods.Where(x => x.UnitId == id).OrderBy(x => x.Id); if (_user.Role < AccessLevelUserRolesEnum.Admin) { goods = goods.Where(x => !x.isDisabled); } pagingParameters.Init(await goods.CountAsync()); HttpContext.Response.Cookies.Append("rowsCount", pagingParameters.CountAllElements.ToString()); if (pagingParameters.PageNum > 1) { goods = goods.Skip(pagingParameters.Skip); } string TypeName = nameof(UnitGoodObjectModel); var qGoods = from good in goods.Include(x => x.Unit).Include(x => x.Group) join UserFavoriteLocator in _context.UserFavoriteLocators on new { ObjectId = good.Id, TypeName, UserId = _user.Id } equals new { UserFavoriteLocator.ObjectId, UserFavoriteLocator.TypeName, UserFavoriteLocator.UserId } into joinFavoriteLocator from isFavoriteMark in joinFavoriteLocator.DefaultIfEmpty() select new { good, isFavoriteMark }; return(new ObjectResult(new ServerActionResult() { Success = true, Info = "Запрос номенклатурнй группы обработан", Status = StylesMessageEnum.success.ToString(), Tag = new { unit.Id, unit.Name, unit.Information, noDelete = await _context.GoodMovementDocumentRows.AnyAsync(x => x.UnitId == id) || pagingParameters.CountAllElements > 0, goods = await qGoods.Take(pagingParameters.PageSize).Select(selectItem => new { selectItem.good.Id, selectItem.good.Name, selectItem.good.Price, selectItem.good.Information, selectItem.good.isReadonly, selectItem.good.isDisabled, selectItem.good.isGlobalFavorite, isUserFavorite = selectItem.isFavoriteMark != null, Group = new { selectItem.good.Group.Id, selectItem.good.Group.Name, selectItem.good.Group.Information }, Unit = new { selectItem.good.Unit.Id, selectItem.good.Unit.Name } }).ToListAsync() } })); }