Exemplo n.º 1
0
        public async Task <IActionResult> Invoice()
        {
            if (TempData["invoice"] != null)
            {
                string serializedData           = TempData["invoice"] as string;
                SharingSelectionModel model     = JsonConvert.DeserializeObject <SharingSelectionModel>(serializedData);
                SharingViewModel      viewModel = await Calculate(model);

                HttpContext.JsReportFeature().Recipe(Recipe.PhantomPdf).OnAfterRender((report) =>
                {
                    DirectoryInfo directoryInfo = System.IO.Directory.CreateDirectory("invoice");
                    Stream content  = report.Content;
                    string fileName = GenerateFileName();
                    string path     = Path.Combine(Directory.GetCurrentDirectory(), "invoice", fileName);

                    using (FileStream fs = System.IO.File.Create(path))
                    {
                        content.CopyTo(fs);
                    }
                    content.Position = 0;
                    //Write Invoice to DB
                    Invoice dbEntry = new Invoice
                    {
                        CreatedDate = DateTime.Now,
                        Filename    = fileName
                    };
                    repo.SaveInvoice(dbEntry);
                });
                return(View(viewModel));
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Base36 encode the model's ID with extra parity bit
        /// </summary>
        /// <param name="model">The incoming model to convert</param>
        /// <returns>Base36 encoded string</returns>
        public async Task <PodcastEntrySharingLink> CreateNewSharingLink(SharingViewModel model)
        {
            var entry = await GetAsync(model.Id);

            if (entry is null)
            {
                return(null);
            }

            var token = TokenGenerator.GenerateToken();

            while (await GetContext()
                   .PodcastEntrySharingLinks
                   .Where(x => x.LinkId == token)
                   .AsNoTracking()
                   .FirstOrDefaultAsync() != null)
            {
                token = TokenGenerator.GenerateToken();
            }

            ;
            var link = new PodcastEntrySharingLink {
                LinkId    = token,
                ValidFrom = model.ValidFrom,
                ValidTo   = model.ValidTo
            };

            if (entry.SharingLinks is null)
            {
                entry.SharingLinks = new List <PodcastEntrySharingLink>();
            }
            entry.SharingLinks.Add(link);
            return(link);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> CloseLimitedAccessForUser(SharingViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _sharingService.CloseLimitedAccessForUser(model.DocumentId, User, model.Email);

                return(Ok());
            }

            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Sharing(SharingSelectionModel model)
        {
            if (ModelState.IsValid)
            {
                SharingViewModel viewModel = await Calculate(model);

                //Save result into TempData
                TempData["invoice"] = JsonConvert.SerializeObject(model);
                return(View(viewModel));
            }
            else
            {
                TempData["message"] = "Please select persons you want to share";
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 5
0
        public async Task <IActionResult> OpenLimitedAccessForUser(SharingViewModel model)
        {
            if (ModelState.IsValid)
            {
                var link = await _sharingService.OpenLimitedAccess(model.DocumentId, User, model.Email);

                if (link != null)
                {
                    var callbackUrl = Url.FileAccessLink(link, Request.Scheme);
                    await _emailService.SendEmailAsync(model.Email, "You have been granted an access to the file",
                                                       $"{User.Identity.Name} has shared a <a href='{callbackUrl}'>file</a> with you");

                    return(RedirectToAction("UserStorage", "Document"));
                }

                return(View("ShareFile", model));
            }

            return(View("ShareFile", model));
        }
Exemplo n.º 6
0
        private async Task <SharingViewModel> Calculate(SharingSelectionModel model)
        {
            SharingViewModel viewModel = new SharingViewModel
            {
                FromDate = model.FromDate,
                ToDate   = model.ToDate
            };

            foreach (string id in model.Ids)
            {
                AppUser user = await userManager.FindByIdAsync(id);

                if (user != null)
                {
                    IEnumerable <Expense> expenses = repo.GetExpenses(user).Where(e => e.ShareExpense && (model.FromDate <= e.Date && e.Date <= model.ToDate));
                    viewModel.AddUser(user.UserName, expenses);
                }
            }
            viewModel.Calculate();
            return(viewModel);
        }
Exemplo n.º 7
0
        public async Task <ActionResult <SharingResultViewModel> > ShareToEmail([FromBody] SharingViewModel model)
        {
            if (string.IsNullOrEmpty(model.Id) || string.IsNullOrEmpty(model.Email))
            {
                return(BadRequest());
            }
            try {
                var entry = await _entryRepository.GetAsync(_applicationUser.Id, model.Id);

                if (entry is null)
                {
                    return(NotFound());
                }
                var link = await _entryRepository.CreateNewSharingLink(model);

                if (link != null)
                {
                    await _unitOfWork.CompleteAsync();

                    var url = Flurl.Url.Combine(new string[] { _sharingSettings.BaseUrl, link.LinkId });
                    await this._mailSender.SendEmailAsync(
                        model.Email,
                        $"{_applicationUser.GetBestGuessName()} shared a link with you",
                        new MailDropin {
                        username = model.Email.Split('@')[0],     //bite me!
                        message  = $"<p>{_applicationUser.GetBestGuessName()} wants to share an audio file with you!</p><br />" +
                                   $"<p>{model.Message}</p>",
                        buttonmessage = "Let me at it!!",
                        buttonaction  = url
                    });

                    return(Ok());
                }
            } catch (Exception e) {
                _logger.LogError(e.Message);
            }
            return(StatusCode(500));
        }
Exemplo n.º 8
0
 public SettingsSharing()
 {
     InitializeComponent();
     DataContext            = new SharingViewModel();
     Model.PropertyChanged += Model_PropertyChanged;
 }
Exemplo n.º 9
0
 public SettingsSharing()
 {
     InitializeComponent();
     DataContext = new SharingViewModel();
     this.AddWidthCondition(1080).Add(v => Grid.Columns = v ? 2 : 1);
 }
Exemplo n.º 10
0
 public SettingsSharing() {
     InitializeComponent();
     DataContext = new SharingViewModel();
     Model.PropertyChanged += Model_PropertyChanged;
 }
Exemplo n.º 11
0
 public SharingController(IUnitOfWork unitOfWork)
 {
     _unitOfWork = unitOfWork;
     _model      = new SharingViewModel();
 }
Exemplo n.º 12
0
        public async Task <ActionResult <SharingResultViewModel> > GenerateSharingLink([FromBody] SharingViewModel model)
        {
            var entry = await _entryRepository.GetAsync(_applicationUser.Id, model.Id);

            if (entry == null)
            {
                return(NotFound());
            }

            var share = await _entryRepository.CreateNewSharingLink(model);

            if (share != null)
            {
                await _unitOfWork.CompleteAsync();

                return(Ok(new SharingResultViewModel {
                    Id = model.Id,
                    ValidFrom = model.ValidFrom,
                    ValidTo = model.ValidTo,
                    Url = Flurl.Url.Combine(_sharingSettings.BaseUrl, share.LinkId)
                }));
            }
            return(BadRequest());
        }