public async Task UpsertFilm(FilmDto filmDto, string currentUserId)
        {
            var film = filmDto.Id > 0
                       ? await _repository.GetAsync(filmDto.Id)
                       : Film.Create();

            if (!film.IsNew && film.AuthorId != currentUserId)
            {
                throw new DomainException("Только автор может изменять фильм");
            }

            film.Name        = filmDto.Name;
            film.Description = filmDto.Description;
            film.AuthorId    = currentUserId;
            film.Year        = filmDto.Year;
            film.DirectorId  = filmDto.DirectorId;

            if (filmDto.Poster != null)
            {
                // Ideally, thumbnail should be created
                film.PosterUrl = await _fileSaver.Save(film.Name, filmDto.Poster);
            }

            await _repository.UpsertAsync(film);
        }
Exemple #2
0
        public ActionResult Move(MoveStockModel input, HttpPostedFileBase requisitionDoc, HttpPostedFileBase authorizationDoc)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.LocationId = new SelectList(Db.Locations, "Id", "Name");
                return(View(input));
            }

            var stock = _stockRepo.Find(input.StockId);

            if (stock == null)
            {
                return(new HttpNotFoundResult("Cannot find Stock with given ID"));
            }

            var movement = new Movement
            {
                DateCreated  = DateTime.UtcNow,
                StockId      = input.StockId,
                ToLocationId = input.LocationId,
                Notes        = input.Notes,
            };

            movement = _itemRepo.MoveStock(movement);

            var movementRepo = new MovementRepository(Db);

            if (requisitionDoc != null)
            {
                movementRepo.AttachRequisitionDoc(movement.Id, _pictureSaver.Save(requisitionDoc));
            }

            if (authorizationDoc != null)
            {
                movementRepo.AttachAuthorizationDoc(movement.Id, _pictureSaver.Save(authorizationDoc));
            }
            var toLocation = Db.Locations.Find(input.LocationId);

            if (toLocation != null)
            {
                LogActivity("moved ", movement.ToString(), movement.Id);

                FlashSuccess(string.Format("Stock item '{0}' has been moved to the location '{1}' successfully", stock.Item.Name,
                                           toLocation.Name));
            }
            return(RedirectToAction("Details", "Items", new { id = stock.ItemId }));
        }
Exemple #3
0
        public async Task <IActionResult> Upload(IFormFile formFile)
        {
            if (!formFile.FileName.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase))
            {
                return(BadRequest());
            }

            await _fileSaver.Save(formFile.FileName, formFile.OpenReadStream());

            return(Ok());
        }
Exemple #4
0
 public void Save(DrawableCollection drawables)
 {
     if (_currentDrawingHasFile)
     {
         _saver.Save(drawables);
     }
     else
     {
         _saver.SaveAsNewFile(drawables);
         _currentDrawingHasFile = true;
     }
 }
Exemple #5
0
        public async Task <IActionResult> Save([FromBody] List <DocumentModel> documents)
        {
            var documentEntities = new List <Document>();


            foreach (var document in documents)
            {
                var base64 = document.ByteArray.Split(',');

                var documentUrl = _fileSaver.Save(document.Name, base64[1]);

                Document documentEntity = new Document
                {
                    Name = document.Name,
                    Url  = documentUrl
                };

                if (document.InstitutionId != null && document.InstitutionId > 0)
                {
                    documentEntity.InstitutionDocumentsMappings = new[] { new InstitutionDocumentsMapping
                                                                          {
                                                                              InstitutionId = document.InstitutionId ?? 0
                                                                          } }
                }
                ;
                else if (document.ContestId != null && document.ContestId > 0)
                {
                    documentEntity.ContestDocumentsMappings = new[] { new ContestDocumentsMapping
                                                                      {
                                                                          InstitutionId = document.ContestId ?? 0
                                                                      } }
                }
                ;
                else if (!string.IsNullOrEmpty(document.UserId))
                {
                    documentEntity.UserDocumentsMappings = new[] { new UserDocumentsMapping
                                                                   {
                                                                       UserId = document.UserId
                                                                   } }
                }
                ;

                documentEntities.Add(documentEntity);

                await _documentsRepository.Save(documentEntity);
            }


            return(Created("/documents/save", documentEntities));
        }
    }
Exemple #6
0
        private void OnReceived(object sender, BasicDeliverEventArgs e)
        {
            if (e?.Body?.Length == 0)
            {
                return;
            }

            var json   = Encoding.UTF8.GetString(e.Body);
            var images = JsonHelper.Deserialize <FileModel[]>(json);

            Console.WriteLine($"{images.Count()} images received.");

            _fileSaver.Save(images);
        }
Exemple #7
0
        private async Task Load(Uri uri, int currentDepth)
        {
            _logger.Info("Downloading content from {0}", uri.OriginalString);

            try
            {
                byte[] byteContent = await _downloader.Load(uri);

                string extension = Path.GetExtension(uri.AbsolutePath);

                string pathToSave = currentDepth == 0
                    ? _downloadPath
                    : Path.Combine(_downloadPath, $"level{currentDepth}");

                var fileName = _fileSaver.Save(byteContent, pathToSave, string.IsNullOrWhiteSpace(extension) ? "html" : extension);

                string fullPath = Path.Combine(pathToSave, fileName);
                _linksMapping.Add(fullPath, uri.OriginalString);

                if (currentDepth >= _referenceDepth)
                {
                    return;
                }

                var content = Encoding.UTF8.GetString(byteContent);
                var links   = _linkParser.GetLinks(content, _extensions);

                foreach (var link in _linkParser.FilterLinks(links, _transferType, _startUri))
                {
                    if (_linksMapping.Select(x => x.Value).FirstOrDefault(x => x.Equals(link.OriginalString)) != null)
                    {
                        _logger.Info($"Duplicate link {link.OriginalString}");
                        continue;
                    }

                    await Load(link, currentDepth + 1);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
            }
        }
Exemple #8
0
        public void Perform()
        {
            var text         = textReader.Read(inputFile);
            var textFiltered = wordsFilter.FilterWords(text);
            var wordsCount   = wordsCounter.CountWords(textFiltered);
            var sizes        = wordsToSizesConverter.GetSizesOf(wordsCount).ToArray();

            sizes = sizes.OrderByDescending(x => x.Item2.Width).ThenBy(x => x.Item2.Height).ToArray();

            CCL.Center = new Point(CCL.Center.X, CCL.Center.Y - sizes[0].Item2.Height);
            for (var i = 0; i < sizes.Length; i++)
            {
                CCL.PutNextRectangle(sizes[i].Item2);
            }

            var bitmap = visualiser.DrawRectangles(CCL, sizes);

            imageSaver.Save(bitmap, outputFile);
        }
Exemple #9
0
        public Result <None> Perform()
        {
            var sizesResult = textReader.Read(inputFile)
                              .Then(wordsFilter.FilterWords)
                              .Then(wordsCounter.CountWords)
                              .Then(wordsToSizesConverter.GetSizesOf)
                              .OnFail(Console.WriteLine);

            if (sizesResult.IsSuccess)
            {
                var sizes = sizesResult.GetValueOrThrow().OrderByDescending(x => x.Item2.Width)
                            .ThenBy(x => x.Item2.Height).ToArray();

                CCL.Center = new Point(CCL.Center.X, CCL.Center.Y - sizes[0].Item2.Height);
                Result <Rectangle> rectangleRes = Result.Fail <Rectangle>("");
                for (var i = 0; i < sizes.Length; i++)
                {
                    rectangleRes = CCL.PutNextRectangle(sizes[i].Item2)
                                   .RefineError("Probably you are giving too small size")
                                   .OnFail(Console.WriteLine);
                    if (!rectangleRes.IsSuccess)
                    {
                        break;
                    }
                }

                if (rectangleRes.IsSuccess)
                {
                    var result = visualiser.DrawRectangles(CCL, sizes).Then(inp => imageSaver.Save(inp, outputFile))
                                 .OnFail(Console.WriteLine);
                    if (result.IsSuccess)
                    {
                        return(Result.Ok());
                    }
                }
            }

            return(Result.Fail <None>("File wasn't created. Try again."));
        }
 public void Save(ref ps.Document doc, IFileSaver fileSaver, FileInfo file)
 {
     fileSaver.Save(ref doc, file);
 }
Exemple #11
0
 public void Save(ref ps.Document doc, IFileSaver fileSaver, FileInfo file)
 {
     fileSaver.Save(ref doc, file);
 }
        public string UploadFile(string fileName, string fileBase64String)
        {
            var base64String = _base64StringExtractor.ExtractBase64String(fileBase64String);

            return(string.IsNullOrEmpty(base64String) ? null : _fileSaver.Save(fileName, base64String));
        }