예제 #1
0
 public List <byte> GetDocument(int id)
 {
     using (var context = new ContextEF())
     {
         return(context.Documents.FirstOrDefault(doc => doc.Id == id)?.File);
     }
 }
예제 #2
0
 public void DeletDocument(int id)
 {
     using (var context = new ContextEF())
     {
         //var document = context.Documents.FirstOrDefault(doc => doc.Id == id);
         var document = new Document {
             Id = id
         };                                       //проверить работает ли так
         context.Documents.Remove(document);
         context.SaveChanges();
     }
 }
예제 #3
0
        public (string, bool) Login(AccountDto accountDto)
        {
            using (var context = new ContextEF())
            {
                var temp = IsAccountExist(accountDto, context);

                if (temp)
                {
                    //TODO: Залогиниться
                    return("Успешно вошли в систему", temp);
                }

                return("Ошибка входа", temp);
            }
        }
예제 #4
0
 public List <DocumentDto> GetDocuments(int authorId)
 {
     using (var context = new ContextEF())
     {
         var documents = context.Documents
                         .Where(doc => doc.Author.Id == authorId)
                         .Select(doc =>
                                 new DocumentDto
         {
             Id           = doc.Id,
             Name         = doc.Name,
             DateTime     = doc.DateCreated,
             DocumentType = DocumentType.Word,         // it's temp solution
             File         = doc.File
         })
                         .ToList();
         return(documents);
     }
 }
예제 #5
0
        public void AddDocument(List <byte> file) //может Document должно быть
        {
            var document = new Document           //затычка
            {
                DocumentType = DocumentType.Word,
                Author       = new Account(),
                Name         = "",
                File         = file //,
                                    //DateCreated = DateTime.UtcNow
            };

            //TODO: fill documet from file and something else data like Author or DocumentType

            using (var context = new ContextEF())
            {
                context.Documents.Add(document);
                context.SaveChanges();
            }
        }
예제 #6
0
        /// <summary>
        /// Класс по работе с БД через EFCore
        /// </summary>
        public (string, bool) AddAccount(AccountDto accountDto)
        {
            using (var context = new ContextEF())
            {
                var temp = IsAccountExist(accountDto, context);

                if (!temp)
                {
                    var account = new Account
                    {
                        Login           = accountDto.Login,
                        CryptedPassword = accountDto.Password //to crypte password before add new account
                    };
                    context.Accounts.Add(account);
                    context.SaveChanges();

                    //TODO: Залогиниться
                    return("Успешно добавлен", temp);
                }

                return("Такой аккаунт уже существует", temp);
            }
        }
예제 #7
0
 //Проверяет  на наличие в БД аккаунта с таким Логином
 private bool IsAccountExist(AccountDto accountDto, ContextEF context)
 {
     return(context.Accounts.Any(x => x.Login == accountDto.Login));
 }