Beispiel #1
0
        public static void Activate(string email)
        {
            var entity = new CreativeNetworkEntities();

            var userToChange = entity.User.FirstOrDefault(a => a.Email == email);
            if (userToChange != null)
                userToChange.IsBlock = false;
            entity.SaveChanges();
        }
Beispiel #2
0
        public static void AddChapter(int creativeId)
        {
            var entity = new CreativeNetworkEntities();
            var creative = entity.Creative.FirstOrDefault(a => a.Id == creativeId);
            int number;
            if (creative.Chapter.Select(a => a.Number).Max() == null)
            {
                number = 0;
            }
            else
            {
                number = (int) creative.Chapter.Select(a => a.Number).Max() +1;
            }

                var chapter = new Chapter
                    {
                        Text = "",
                        Name = "Chapter " + number.ToString(),
                        Number = number,

                    };
            entity.Creative.FirstOrDefault(a => a.Id == creativeId).Chapter.Add(chapter);
            entity.SaveChanges();
        }
Beispiel #3
0
        public static void AddUser(User user)
        {
            var entity = new CreativeNetworkEntities();

            entity.User.Add(user);
            entity.SaveChanges();
        }
Beispiel #4
0
        public static void AddCreative(Creative creative, string tags)
        {
            var entity = new CreativeNetworkEntities();
            if (tags != null)
            {
                string[] tagList = tags.Split(new Char[] { ' ', ',' });

                foreach (var item in tagList.Distinct())
                {
                    if (string.IsNullOrEmpty(item) || item.Length > 50) continue;
                    var tag = new Tag
                    {
                        Name = item,
                    };
                    tag.Name = tag.Name.TrimEnd().ToLower();
                    if (entity.Tag.FirstOrDefault(a => a.Name == tag.Name) != null)
                    {
                        tag = entity.Tag.FirstOrDefault(a => a.Name == tag.Name);
                    }
                    else
                    {
                        entity.Tag.Add(tag);
                    }
                    creative.Tag.Add(tag);
                    var ers = entity.GetValidationErrors();
                    entity.SaveChanges();
                }
            }
            entity.Creative.Add(creative);
            var s = entity.GetValidationErrors();
            entity.SaveChanges();
        }
Beispiel #5
0
        public static void SaveChapter(int id, string title, string text)
        {
            var entity = new CreativeNetworkEntities();

            var chapter = entity.Chapter.FirstOrDefault(c => c.Id == id);
            chapter.Text = text;
            chapter.Name = title;
            entity.Chapter.Attach(chapter);
            entity.Entry(chapter).State = EntityState.Modified;
            entity.SaveChanges();
        }
Beispiel #6
0
        public static void Rate(User user, Creative creative, int rating)
        {
            var entity = new CreativeNetworkEntities();

            var creativeLikes = entity.CreativeLikes.FirstOrDefault(a => a.UserId == user.Id && a.CreativeId == creative.Id);
            if (creativeLikes != null)
            {
                if (creativeLikes.Rating == rating)
                {
                    entity.CreativeLikes.Remove(creativeLikes);
                    entity.SaveChanges();
                    return;
                }
                else
                {
                    entity.CreativeLikes.Remove(creativeLikes);
                }
            }

            var newRate = new CreativeLikes()
            {
                UserId = user.Id,
                CreativeId = creative.Id,
                Rating = rating,
            };
            entity.CreativeLikes.Add(newRate);

            entity.SaveChanges();
        }
Beispiel #7
0
        public static bool MakeAdmin(int userId)
        {
            var entity = new CreativeNetworkEntities();
            var user = entity.User.FirstOrDefault(a => a.Id == userId);

            if (user.IsBlock == true) return false;
            user.RoleId = 2;

            entity.SaveChanges();
            return (user.RoleId == 2);
        }
Beispiel #8
0
        public static void DeleteCreative(int id)
        {
            var entity = new CreativeNetworkEntities();

            var creative = entity.Creative.FirstOrDefault(a => a.Id == id);

            creative.Tag.Clear();
            var chapters = creative.Chapter.ToArray();
            foreach (var item in chapters)
            {
                entity.Chapter.Remove(item);
            }

            creative.Chapter.Clear();
            var ratings = entity.CreativeLikes.Where(a => a.CreativeId == id).ToArray();

            foreach (var item in ratings)
            {
                entity.CreativeLikes.Remove(item);
            }
            entity.Creative.Remove(creative);
            entity.SaveChanges();

            var tags = creative.Tag.ToArray();
            foreach (var item in tags)
            {
                if (entity.Tag.FirstOrDefault(a => a.Id == item.Id).Creative.Count == 0)
                {
                    entity.Tag.Remove(item);
                }
            }
        }
Beispiel #9
0
        public static void DeleteChapter(int id)
        {
            var entity = new CreativeNetworkEntities();

            entity.Chapter.Remove(entity.Chapter.FirstOrDefault(a => a.Id == id));
            entity.SaveChanges();
        }
Beispiel #10
0
        public static void ChangePassword(int userId, string newPasswordHash)
        {
            var entity = new CreativeNetworkEntities();
            var user = entity.User.FirstOrDefault(a => a.Id == userId);

            user.Password = newPasswordHash;

            entity.SaveChanges();
        }
Beispiel #11
0
        public static void ChangeNumber(int chapterId, int number)
        {
            var entity = new CreativeNetworkEntities();

            var chapter = entity.Chapter.FirstOrDefault(c => c.Id == chapterId);
            chapter.Number = number;
            entity.Chapter.Attach(chapter);
            entity.Entry(chapter).State = EntityState.Modified;
            entity.SaveChanges();
        }
Beispiel #12
0
        public static bool Block(int userId)
        {
            var entity = new CreativeNetworkEntities();
            var user = entity.User.FirstOrDefault(a => a.Id == userId);

            user.IsBlock = !user.IsBlock;

            entity.SaveChanges();
            return (bool)user.IsBlock;
        }