Пример #1
0
 public AuthorDTO GetAuthorByName(string fullName)
 {
     using (var context = new MusicHubDb())
     {
         return(context.Authors.Include("Songs").Where(x => x.FullName == fullName).ToList().Select(y => AuthorDTO.FromEntity(y)).FirstOrDefault());
     }
 }
Пример #2
0
        public void AddAuthor(string fullName, string password)
        {
            using (var context = new MusicHubDb())
            {
                context.Authors.Add(new Author()
                {
                    Id       = context.Authors.ToList().Count(),
                    FullName = fullName,
                    Password = password
                });

                context.SaveChanges();
            }
        }
Пример #3
0
        public void DeleteAuthor(string fullName, string password)
        {
            using (var context = new MusicHubDb())
            {
                Author author = context.Authors.Where(x => x.FullName == fullName && x.Password == password).FirstOrDefault();

                try
                {
                    context.Entry(author).State = EntityState.Deleted;
                }
                catch (ArgumentNullException)
                {
                    Console.WriteLine("Error - wrong password"); //could not be the wrong name as that is checked earlier (.Presentation via GetAuthorByName method)
                }

                context.SaveChanges();
            }
        }