Beispiel #1
0
        public User Register(string username, string password, string email)
        {
            var user = new User()
            {
                Username = username,
                Email    = email,
                Password = password
            };

            context.Add(user);
            context.SaveChanges();
            return(user);
        }
        public Tag AddTag(string name)
        {
            var tag = new Tag()
            {
                Name = name
            };

            context.Add(tag);
            context.SaveChanges();

            return(tag);
        }
Beispiel #3
0
        public Town Add(string townName, string countryName)
        {
            var town = new Town()
            {
                Name    = townName,
                Country = countryName
            };

            context.Add(town);
            context.SaveChanges();

            return(town);
        }
Beispiel #4
0
        public AlbumTag AddTagTo(int albumId, int tagId)
        {
            var album = context.Albums.SingleOrDefault(p => p.Id == albumId);
            var tag   = context.Tags.SingleOrDefault(p => p.Id == tagId);

            if (album == null || tag == null)
            {
                throw new ArgumentException($"Invalid album or tag id!");
            }

            var albumTag = new AlbumTag()
            {
                Album   = album,
                AlbumId = albumId,
                Tag     = tag,
                TagId   = tagId
            };

            context.Add(albumTag);
            context.SaveChanges();

            return(albumTag);
        }
        public Album Create(int userId, string albumTitle, string BgColor, string[] tags)
        {
            Color color;

            try
            {
                color = Enum.Parse <Color>(BgColor);
            }
            catch
            {
                throw new ArgumentException(String.Format(ColorNotFound, BgColor));
            }

            var album = new Album
            {
                Name            = albumTitle,
                BackgroundColor = color,
                IsPublic        = true
            };


            context.Add(album);
            //context.SaveChanges();

            var user = context.Users.SingleOrDefault(p => p.Id == userId);

            var albumRole = new AlbumRole()
            {
                AlbumId = album.Id,
                User    = user,
                Role    = Role.Owner
            };

            context.AlbumRoles.Add(albumRole);

            var albumTags = new List <AlbumTag>();

            foreach (var t in tags)
            {
                var tag = context.Tags.FirstOrDefault(p => p.Name == t);


                if (tag == null)
                {
                    throw new ArgumentException(InvalidTags);
                }



                var albumTag = new AlbumTag()
                {
                    AlbumId = album.Id,
                    Tag     = tag
                };

                albumTags.Add(albumTag);
            }

            context.AlbumTags.AddRange(albumTags);
            context.SaveChanges();

            return(album);
        }