/** * In this method the equipment feedback is saved to the database. */ private async Task SaveToDatabase(InspectionItemModel device, InspectionResult result, bool vera, ObservableCollection <MediaFile> photos, double?weight, int?FeedbackTypeId = null, string remarks = null) { try { sLogger.SavedFeedbackToDatabaseStarted(); var equipmentFeedback = new InspectionEquipmentFeedbackRepresentationForCreation(); equipmentFeedback.EquipmentId = SelectedItem.Equipment.EquipmentId; equipmentFeedback.Weight = weight; equipmentFeedback.Status = result.ToString(); equipmentFeedback.FeedbackTypeId = FeedbackTypeId; equipmentFeedback.Remark = remarks; equipmentFeedback.TimeCompleted = DateTime.Now; equipmentFeedback.OperatorId = UserService.Operator.UserId; equipmentFeedback.EquipmentLocationName = SelectedItem.Equipment.EquipmentLocation.Name; equipmentFeedback.EquipmentLocationDescription = SelectedItem.Equipment.EquipmentLocation.Description; equipmentFeedback.Vera = vera; var response = await Client.PostEnsureAsync("fire-safety/inspectionequipmentfeedback", equipmentFeedback); var href = response.Links.GetLink(WebApi.InspectionEquipmentFeedbacks.HypermediaLinks.Attachment); DevicesInspected.Where(x => x.Equipment.EquipmentId == device.Equipment.EquipmentId).SingleOrDefault().Equipment.LastFeedbackID = Int32.Parse(href.Href.Split('/')[4]);; sLogger.SavedFeedbackToDatabaseCompleted(); if (photos != null) { sLogger.SaveFeedbackPhotosToDatabaseStarted(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <IFileInfo, InspectionEquipmentFeedbackAttachmentRepresentationForCreation>().ForMember(dest => dest.DateCreated, opt => opt.MapFrom(src => src.CreationTime)).ForMember(dest => dest.FileName, opt => opt.MapFrom(src => src.Name)).ForMember(dest => dest.Size, opt => opt.MapFrom(src => src.Length)); }); mapper = config.CreateMapper(); foreach (MediaFile photo in photos) { IFileInfo metaData = GetService <IFileSystemService>().GetFileInfo(photo.Path); var attachment = mapper.Map <InspectionEquipmentFeedbackAttachmentRepresentationForCreation>(metaData); byte[] bytes = File.ReadAllBytes(photo.Path); var ms = photo.GetStream(); var attachmentresponse = await Client.PostMultipartAsync(href.AsUri(), attachment, ms, CancellationToken.None); } sLogger.SaveFeedbackPhotosToDatabaseCompleted(); } } catch (Exception e) { UserDialogs.Instance.Alert("Er is een probleem opgelopen tijdens het opslaan", "Save Error", "ok"); sLogger.SavedFeedbackToDatabaseFailed(e); } }