public List <byte> GetDocument(int id) { using (var context = new ContextEF()) { return(context.Documents.FirstOrDefault(doc => doc.Id == id)?.File); } }
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(); } }
public (string, bool) Login(AccountDto accountDto) { using (var context = new ContextEF()) { var temp = IsAccountExist(accountDto, context); if (temp) { //TODO: Залогиниться return("Успешно вошли в систему", temp); } return("Ошибка входа", temp); } }
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); } }
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(); } }
/// <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); } }
//Проверяет на наличие в БД аккаунта с таким Логином private bool IsAccountExist(AccountDto accountDto, ContextEF context) { return(context.Accounts.Any(x => x.Login == accountDto.Login)); }