public async Task <int> SaveExpert(ExpertModel model)
        {
            var entity = new ExpertMaterial
            {
                Caption    = model.Title,
                Content    = model.Content,
                LastChange = DateTime.Now,
                User       = await this.usersService.GetCurrentApplicationUser(),
            };

            model.Files?.ForEach(f =>
            {
                var fileEntity = new ExpertDocument
                {
                    Id         = f.Id,
                    Content    = Convert.FromBase64String(f.Base64Content),
                    MimeType   = f.MimeType,
                    Name       = f.Filename,
                    LanguageId = f.Language.Id
                };
                entity.ExpertDocuments.Add(fileEntity);
            });

            var caseInserted = this.context.ExpertMaterials.Add(entity);

            await this.context.SaveChangesAsync();

            return(caseInserted.Entity.Id);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Choose mode - basic, pro, expert");
            string mode = Console.ReadLine().ToLower();

            DocumentProgram docProgram = new DocumentProgram();

            switch (mode)
            {
            case "basic":
                docProgram = new DocumentProgram();
                break;

            case "pro":
                docProgram = new ProDocumentProgram();
                break;

            case "expert":
                docProgram = new ExpertDocument();
                break;

            default:
                Console.WriteLine("Wrong mode");
                break;
            }
            docProgram.OpenDocument();
            docProgram.EditDocument();
            docProgram.SaveDocument();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            string key;

            while (true)
            {
                try
                {
                    Console.WriteLine("Enter key");
                    key = Console.ReadLine();
                    switch (key)
                    {
                    case "basic":
                        Console.Clear();
                        DocumentProgram documentProgram = new DocumentProgram();
                        documentProgram.OpenDocument();
                        documentProgram.EditDocument();
                        documentProgram.SaveDocument();
                        break;

                    case "pro":
                        Console.Clear();
                        DocumentProgram proDocumentProgram = new ProDocumentProgram();
                        proDocumentProgram.OpenDocument();
                        proDocumentProgram.EditDocument();
                        proDocumentProgram.SaveDocument();
                        break;

                    case "expert":
                        Console.Clear();
                        DocumentProgram expertDocument = new ExpertDocument();
                        expertDocument.OpenDocument();
                        expertDocument.EditDocument();
                        expertDocument.SaveDocument();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
        static void Main(string[] args)
        {
            string keyword;

            do
            {
                Console.WriteLine("Please enter keyword: ");
                keyword = Console.ReadLine();

                if (keyword == "basic")
                {
                    DocumentProgram docProgram = new DocumentProgram();

                    docProgram.OpenDocument();
                    docProgram.EditDocument();
                    docProgram.SaveDocument();
                }

                else if (keyword == "pro")
                {
                    DocumentProgram docProgram = new ProDocumentProgram();

                    docProgram.OpenDocument();
                    docProgram.EditDocument();
                    docProgram.SaveDocument();
                }

                else if (keyword == "expert")
                {
                    DocumentProgram docProgram = new ExpertDocument();

                    docProgram.OpenDocument();
                    docProgram.EditDocument();
                    docProgram.SaveDocument();
                }
                else
                {
                    Console.WriteLine("It is not correct keyword");
                }
            } while (!(keyword == "basic" || keyword == "pro" || keyword == "expert"));
        }
        public async Task EditExpert(ExpertModel model, int id)
        {
            var expertInfo = await this.context.ExpertMaterials.Where(x => x.Id == id).Select(x => new
            {
                Expert       = x,
                OrgShortName = x.User.Organization.ShortName,
                x.UserId,
                Files = x.ExpertDocuments.Select(z => z.Id)
            }).SingleAsync();

            var hasRightToEdit = this.HasEditDeleteRights(expertInfo.UserId, expertInfo.OrgShortName);

            if (!hasRightToEdit)
            {
                throw new NotAuthorizedException();
            }

            var oldRecord = expertInfo.Expert;

            if (oldRecord == null)
            {
                throw new NotFoundException($"Expert material with id {id} not found");
            }

            oldRecord.Content    = model.Content;
            oldRecord.LastChange = DateTime.Now;
            oldRecord.Caption    = model.Title;

            var currentFileIds = expertInfo.Files.ToList();
            var missingOldIds  = currentFileIds.Except(model.Files.Select(x => x.Id)).ToList(); //delete

            foreach (var oldId in missingOldIds)
            {
                var entity = new ExpertDocument {
                    Id = oldId
                };
                var entityEntry = this.context.ExpertDocuments.Attach(entity);
                entityEntry.State = EntityState.Deleted;
            }

            var newFiles = model.Files.Where(x => !currentFileIds.Contains(x.Id)); //add

            foreach (var newFile in newFiles)
            {
                var fileEntity = new ExpertDocument
                {
                    Id               = newFile.Id,
                    Content          = Convert.FromBase64String(newFile.Base64Content), // case if this is null - exception?
                    MimeType         = newFile.MimeType,
                    Name             = newFile.Filename,
                    LanguageId       = newFile.Language.Id,
                    ExpertMaterialId = id
                };
                this.context.ExpertDocuments.Add(fileEntity);
            }

            var log = this.mapper.Map <ExpertMaterialsLog>(oldRecord);

            log.UserId = this.currentUserService.GetCurrentUserIdClaim();
            this.context.ExpertMaterialsLog.Add(log);
            await this.context.SaveChangesAsync();
        }