public bool EditDocument(int id, string value, aspnet_Users user, out string msg) { bool res = false; var doc = new udovika_contract(); msg = ""; try { if (!GetPermissionAccessDocument(user)) { msg = "Недостаточно прав для редактирования."; return(res); } else { doc = db.GetDocument(id); if (doc != null) { doc.number = value; SaveDocument(doc, user, out msg); res = true; } } } catch (Exception ex) { _debug(ex, doc, ""); } return(res); }
public DocumentModule(IRepository documents, IImageRepository images, IRatingRepository ratings, IReviewRepository reviews, IFavoritesRepository favorites, IEnvironmentPathProvider pathProvider) : base("/documents") { Get["/{id}/thumbnail"] = args => { var doc = documents.GetDocument(args.id, true); string img = images.GetDocumentImage(args.id); if (String.IsNullOrEmpty(img)) { return ResolvePlaceHolderImageForDocumentType(pathProvider, doc); } return Response.AsFile(Path.Combine(pathProvider.GetImageCachePath(), img)); }; Get["/{id}"] = args => { Document document = documents.GetDocument(args.id, false); return Response.AsJson(DtoMaps.Map(document, favorites, Context.GetUserInfo())); }; Get["/{id}/rating"] = args => { try { DocumentRating rating = ratings.GetDocumentRating(args.id); return Response.AsJson(new DocumentRatingDto { MaxScore = rating.MaxScore, Score = rating.Score, Source = rating.Source, SourceUrl = rating.SourceUrl, HasRating = true }).AsCacheable(DateTime.Now.AddDays(1)); } catch { return new DocumentRatingDto {Success = true, HasRating = false}; } }; Get["/{id}/review"] = args => { string review = reviews.GetDocumentReview(args.id); return Response.AsJson(new DocumentReviewDto{ Review = review, Url = "" }).AsCacheable(DateTime.Now.AddDays(1)); }; Get["/search"] = _ => { string query = Request.Query.query.HasValue ? Request.Query.query : null; if (null == query) throw new InvalidOperationException("Ingenting å søke etter."); return Response.AsJson(documents.Search(query).Select(doc => DtoMaps.Map(doc, favorites, Context.GetUserInfo())).ToArray()).AsCacheable(DateTime.Now.AddHours(12)); }; }
public void Execute(IndoorAssetReportMessage message) { // if edge doesn't exist if (_edgeRepo.RetrieveAsync(message.HardwareSerial).Result == null) { _edgeRepo.SetAsync(message.HardwareSerial, new EdgeData()).Wait(); Console.WriteLine($"added new edge ({message.HardwareSerial})"); } var newEdgeRef = _edgeRepo.GetDocument(message.HardwareSerial); var batch = _firebaseClient.GetFirestoreDb().StartBatch(); foreach (var payload in message.IndoorTagPayloadInfo) { _assetService.UpdateEdgeAsync(batch, new AssetData { MacAddress = payload.MacAddress, LastReportTime = Timestamp.GetCurrentTimestamp(), BatteryLevel = payload.BatteryLevel, SignalStrength = payload.Rss, EdgeRef = newEdgeRef }).Wait(); } batch.CommitAsync().Wait(); }
public void SetEdge(string assetId, string targetEdgeId) { this.Execute(() => { var assetSvc = sp.GetService <IAssetService>(); var edgeRepo = sp.GetService <IRepository <EdgeData> >(); var batch = sp.GetService <IFirebaseClient>().GetFirestoreDb().StartBatch(); assetSvc.UpdateEdgeAsync(batch, _repo.GetDocument(assetId), edgeRepo.GetDocument(targetEdgeId)).Wait(); batch.CommitAsync().Wait(); }); }
public vas_documents GetDocument(int id, aspnet_Users user, out string msg) { var res = new vas_documents(); msg = ""; try { res = db.GetDocument(id); if (!_canAccessToDocument(user, res)) { msg = "Нет прав для данной операции"; return(res = null); } } catch (Exception ex) { _debug(ex, new { documentID = id, userName = user.UserName }); res = null; msg = "Сбой при выполнеии операции"; } return(res); }
public async Task UpdateEdgeAsync(WriteBatch batch, AssetData reportedAssetData) { var reportedAssetRef = _assetRepo.GetDocument(reportedAssetData.MacAddress); DocumentReference reportedEdgeRef = reportedAssetData.EdgeRef; if (!await UpdateEdgeAsync(batch, reportedAssetRef, reportedEdgeRef).ConfigureAwait(false)) { // add a new asset document batch.Set(reportedAssetRef, reportedAssetData); // add the reported asset's reference to the reported edge AddAssetRefToEdge(batch, reportedAssetRef, reportedEdgeRef); } }
public FavoritesModule(IFavoritesRepository favorites, IRepository documents) : base("/favorites") { this.RequiresAuthentication(); Get["/"] = _ => favorites.GetFavorites(Context.GetUserInfo()).Select(MapToDto).ToArray(); Delete["/{documentId}"] = args => { var document = documents.GetDocument(args.documentId, true); favorites.RemoveFavorite(document, Context.GetUserInfo()); return new RequestReplyDto { Success = true }; }; Put["/{documentId}"] = args => { var document = documents.GetDocument(args.documentId, true); favorites.AddFavorite(document, Context.GetUserInfo()); return new RequestReplyDto { Success = true }; }; }
public molchanov_documents GetDocument(int id, out string msg, aspnet_Users user) { msg = ""; molchanov_documents res; try { if (!_canAccessToItem(user)) { msg = "Нет прав на получение элемента по id"; res = null; } else { res = _db.GetDocument(id); } } catch (Exception e) { _debug(e, new { }, "Ошибка возникла при получении элемента по id"); res = null; } return(res); }
/// <summary> /// Attach asset between 2 edges to mimic moving asset between 2 edges /// </summary> public void ChangeAssetEdges(string assetId, string edgeId1, string edgeId2) { this.Execute(() => { var assetSvc = sp.GetService <IAssetService>(); var edgeRepo = sp.GetService <IRepository <EdgeData> >(); string targetEdgeId = edgeId1; var batch = sp.GetService <IFirebaseClient>().GetFirestoreDb().StartBatch(); do { Console.WriteLine($"Moving asset ({assetId}) to edge ({targetEdgeId}) ..."); assetSvc.UpdateEdgeAsync(batch, _repo.GetDocument(assetId), edgeRepo.GetDocument(targetEdgeId)).Wait(); batch.CommitAsync().Wait(); targetEdgeId = targetEdgeId == edgeId1 ? edgeId2 : edgeId1; Console.WriteLine("Input 'q' to quit ..."); }while (Console.ReadLine() != "q"); }); }
public static ReservationDto Map(Reservation reservation, IRepository documents) { DateTime holdEnd; DateTime holdFrom; DateTime holdTo; DateTime.TryParse(reservation.HoldRequestEnd, out holdEnd); DateTime.TryParse(reservation.HoldRequestFrom, out holdFrom); DateTime.TryParse(reservation.HoldRequestTo, out holdTo); return new ReservationDto { Document = Map(documents.GetDocument(reservation.DocumentNumber, true)), Reserved = holdFrom, ReadyForPickup = !UnavailableStatuses.Contains(reservation.Status), // business logic should not be here! :( PickupLocation = reservation.PickupLocation, PickupDeadline = holdTo }; }
//public void Add(string edgeId, string description) //public void Add(string edgeId) //{ // this.Execute(() => { // Console.WriteLine($"Adding edge {edgeId} ..."); // _svc.AddAsync(edgeId, new EdgeData()).Wait(); // Console.WriteLine("Finished adding edge"); // }); //} public void LinkMarker(string edgeId, string floorPlanId, string edgeMarkerId) { this.Execute(() => { var _floorplanSvc = sp.GetService <IRepository <FloorplanData> >(); var _edgeMarkerSvc = sp.GetService <IEdgeMarkerRepository>(); _edgeMarkerSvc.FloorplanId = floorPlanId; Console.WriteLine($"link edge {edgeId} to edge mark {edgeMarkerId} of floorplan {floorPlanId}"); var edge = _svc.GetDocument(edgeId); var edgeMarker = _edgeMarkerSvc.GetDocument(edgeMarkerId); //var floorplan = _floorplanSvc.RetrieveAsync(floorPlanId).Result; //FirestoreUtils.PrintObject(floorplan); //Console.WriteLine(""); edge.UpdateAsync(nameof(EdgeData.EdgeMarkerRef), edgeMarker).Wait(); edgeMarker.UpdateAsync(nameof(EdgeMarkerData.EdgeRef), edge).Wait(); }); }
public static LibrarylistDto Map(LibraryList list, IRepository documents = null) { if (null != documents) { return new LibrarylistDto { Id = list.Id, Name = list.Name, Documents = list.Documents.Count > 0 ? list.Documents.Select(Map).ToList() : list.DocumentNumbers.Keys.Select(dn => Map(documents.GetDocument(dn, true))).ToList() }; } return new LibrarylistDto { Id = list.Id, Name = list.Name }; }
private void ProcessDocument(WsResult item, Rizeni rizeni) { if (!string.IsNullOrEmpty(item.DokumentUrl) && !IgnoreDocuments) { var document = Repository.GetDocument(item.Id.ToString()) ?? new Dokument { Id = item.Id.ToString(), SpisovaZnacka = item.SpisovaZnacka, }; document.Url = item.DokumentUrl; document.DatumVlozeni = item.DatumZalozeniUdalosti; document.Popis = item.PopisUdalosti; document.Oddil = item.Oddil; Repository.SetDocument(document); rizeni.PosledniZmena = item.DatumZalozeniUdalosti; GlobalStats.DocumentCount++; } }
public Dokument GetDocument(string id) => UnderlyingRepository.GetDocument(id);
public DocumentDetails GetDocument(string documentId) { var document = repository.GetDocument(documentId); return(TransformFull(document)); }
public IActionResult Document(int id) { var document = _repo.GetDocument(id); return(PartialView("_Document", document)); }
public UserModule(IRepository documents) : base("/user") { this.RequiresAuthentication(); Get["/notifications/count"] = args => { //var since = Request.Query.since.HasValue ? Request.Query.since : DateTime.MinValue; // we have no idea when a notification was created. Or rather, all notifications are always created 'now'... return new NotificationCountDto {Count = Context.GetUserInfo().Notifications.Count()}; }; Get["/info"] = _ => { var user = Context.GetAlephUserIdentity(); UserInfo results = documents.GetUserInformation(user.UserName, user.Password); var reservationsList = results.Reservations ?? new List<Reservation>(); var finesList = results.ActiveFines ?? new List<Fine>(); var loansList = results.Loans ?? new List<Loan>(); var notificationList = results.Notifications ?? new List<Notification>(); var reservations = reservationsList.Select(r => DtoMaps.Map(r, documents)); var fines = finesList.Select(f => new FineDto { Date = ParseDateString(f.Date), Description = f.Description, Document = String.IsNullOrEmpty(f.DocumentNumber) ? null : DtoMaps.Map(documents.GetDocument(f.DocumentNumber, true)), Status = f.Status, Sum = f.Sum }).OrderByDescending(f => f.Date); var loans = loansList.Select(l => new LoanDto { Document = String.IsNullOrEmpty(l.DocumentNumber) ? null : DtoMaps.Map(documents.GetDocument(l.DocumentNumber, true)), AdminisrtativeDocumentNumber = l.AdminisrtativeDocumentNumber, Barcode = l.Barcode, DocumentNumber = l.DocumentNumber, DocumentTitle = l.DocumentTitle, DueDate = ParseDateString(l.DueDate), ItemSequence = l.ItemSequence, ItemStatus = l.ItemStatus, LoanDate = ParseDateString(l.LoanDate), LoanHour = l.LoanHour, Material = l.Material, OriginalDueDate = ParseDateString(l.OriginalDueDate), SubLibrary = l.SubLibrary }); var notifications = notificationList.Select(n => new NotificationDto { Content = n.Content, DocumentNumber = n.DocumentNumber, DocumentTitle = n.DocumentTitle, Title = n.Title, Type = n.Type }); var userDto = new UserInfoDto { BorrowerId = results.BorrowerId, Balance = results.Balance, CashLimit = results.CashLimit, CellPhoneNumber = results.CellPhoneNumber, CityAddress = results.CityAddress, DateOfBirth = results.DateOfBirth, Email = results.Email, HomeLibrary = results.HomeLibrary, HomePhoneNumber = results.HomePhoneNumber, Id = results.Id, IsAuthorized = results.IsAuthorized, Name = results.Name, PrefixAddress = results.PrefixAddress, StreetAddress = results.StreetAddress, Zip = results.Zip, Reservations = reservations, Fines = fines, Loans = loans, Notifications = notifications }; return userDto; }; }