Beispiel #1
0
 public string GetEmailAddress(int userId)
 {
     using (var context = new IdeaPoolEntities())
     {
         return(context.Users.Where(user => user.Id == userId).Select(x => x.Email).SingleOrDefault());
     }
 }
Beispiel #2
0
        public int Update(IdeaDataObject ideaData)
        {
            using (var context = new IdeaPoolEntities())
            {
                int ideastatusid = context.IdeaStatus
                                   .Where(x => x.Key == (ideaData.IsDraft ? IdeaStatusKeys.DRAFT : IdeaStatusKeys.SUBMITTED))
                                   .Single().Id;

                Idea idea = context.Ideas
                            .Where(x => x.Id == ideaData.Id)
                            .Include(x => x.Files)
                            .Include(x => x.IdeasFieldOfWaters)
                            .Single();
                bool isInDraftBeforeUpdate = idea.IsDraft;
                idea.IdeaStatusId = ideastatusid;
                idea.PlainContent = ideaData.Description;
                idea.HtmlContent  = ideaData.DescriptionHtml;
                idea.Title        = ideaData.Title;
                idea.LastUpdated  = DateTime.UtcNow;
                idea.IsDraft      = ideaData.IsDraft;
                if (ideaData.IsNew)
                {
                    idea.CreatedDate = DateTime.UtcNow;
                }
                UpdateFiles(context, ideaData.Files, idea);
                UpdateFieldOfWater(context, ideaData.FieldOfWater, idea);
                if (!isInDraftBeforeUpdate)
                {
                    InsertIdeaHistory(context, idea.Id, idea.UserId, ActivityKeys.UPDATE_IDEA_DETAILS, ideaData.Reason);
                }
                context.Entry(idea).State = EntityState.Modified;
                context.SaveChanges();
                return(idea.Id);
            }
        }
Beispiel #3
0
        private void UpdateFieldOfWater(IdeaPoolEntities context, List <FieldOfWaterDataObject> fieldOfWaters, Idea ideaData)
        {
            List <int> fieldOfWaterIds = new List <int>();

            foreach (IdeasFieldOfWater fieldOfWater in ideaData.IdeasFieldOfWaters.ToList())
            {
                if (!fieldOfWaters.Any(x => x.Id == fieldOfWater.FieldOfWaterId))
                {
                    context.IdeasFieldOfWaters.Remove(fieldOfWater);
                }
                else
                {
                    if (fieldOfWater.FieldOfWaterId == FIELDOFWATER_OTHER_ID)
                    {
                        var other = fieldOfWaters.Single(x => x.Id == FIELDOFWATER_OTHER_ID);
                        if (fieldOfWater.Description != other.Description)
                        {
                            fieldOfWater.Description          = other.Description;
                            context.Entry(fieldOfWater).State = EntityState.Modified;
                        }
                    }
                    fieldOfWaterIds.Add(fieldOfWater.FieldOfWaterId);
                }
            }
            fieldOfwaterData.InsertIdeaFieldOfWater(context, ideaData.Id, fieldOfWaters.Where(x => !fieldOfWaterIds.Contains(x.Id)).ToList());
        }
Beispiel #4
0
        public IdeaDataObject Fetch(int ideaId, FetchMode mode)
        {
            IdeaDataObject ideaData = null;

            using (var context = new IdeaPoolEntities())
            {
                Idea idea  = null;
                var  query = context.Ideas
                             .Include(x => x.User)
                             .AsQueryable();

                if (mode == FetchMode.Full)
                {
                    query = query
                            .Include(x => x.Files)
                            .Include(x => x.IdeaStatus)
                            .Include(x => x.IdeasFieldOfWaters)
                            .Include(x => x.IdeasFieldOfWaters.Select(y => y.FieldOfWater));
                }

                idea     = query.SingleOrDefault(x => x.Id == ideaId);
                ideaData = MapIdea(idea, mode);
            }
            return(ideaData);
        }
Beispiel #5
0
        public FileDataObject FetchThumbnail(int fileId, int ideaId)
        {
            FileDataObject file = null;

            using (var context = new IdeaPoolEntities())
            {
                var selectedFile = context.Files
                                   .Where(x => x.Id == fileId && x.IdeaId == ideaId)
                                   .Select(x => new
                {
                    x.Id,
                    x.Thumbnail,
                    x.ContentType,
                    x.Name
                }).SingleOrDefault();
                if (selectedFile != null)
                {
                    file = new FileDataObject
                    {
                        Id              = selectedFile.Id,
                        Thumbnail       = selectedFile.Thumbnail,
                        ThumbnailBase64 = Convert.ToBase64String(selectedFile.Thumbnail),
                        ContentType     = selectedFile.ContentType,
                        Name            = selectedFile.Name
                    };
                }
            }
            return(file);
        }
Beispiel #6
0
        public FileDataObject Fetch(int ideaId, int fileId)
        {
            FileDataObject file = null;

            using (var context = new IdeaPoolEntities())
            {
                var selectedFile = context.Files
                                   .Where(x => x.Id == fileId && x.IdeaId == ideaId)
                                   .Select(x => new
                {
                    x.Id,
                    x.Content,
                    x.ContentType,
                    x.Name
                }).SingleOrDefault();
                if (selectedFile != null)
                {
                    file = new FileDataObject
                    {
                        Id          = selectedFile.Id,
                        Content     = selectedFile.Content,
                        ContentType = selectedFile.ContentType,
                        Name        = selectedFile.Name
                    };
                }
            }
            return(file);
        }
Beispiel #7
0
        public int Insert(IdeaDataObject idea)
        {
            int id = -1;

            using (var context = new IdeaPoolEntities())
            {
                int ideastatusid = context.IdeaStatus
                                   .Where(x => x.Key == (idea.IsDraft ? IdeaStatusKeys.DRAFT : IdeaStatusKeys.SUBMITTED))
                                   .Single().Id;
                Idea ideaData = new Idea
                {
                    Title        = idea.Title,
                    HtmlContent  = idea.DescriptionHtml,
                    PlainContent = idea.Description,
                    UniqueId     = Guid.NewGuid(),
                    UserId       = idea.UserId,
                    CreatedDate  = DateTime.UtcNow,
                    LastUpdated  = DateTime.UtcNow,
                    IdeaStatusId = ideastatusid,
                    IsDraft      = idea.IsDraft
                };
                fieldOfwaterData.InsertIdeaFieldOfWater(context, ideaData, idea.FieldOfWater);
                fileData.Insert(context, idea.Files, ideaData);
                context.Ideas.Add(ideaData);
                context.SaveChanges();
                id = ideaData.Id;
            }
            return(id);
        }
Beispiel #8
0
        public UserSearchResults Search(UserSearchSettings searchsettings)
        {
            UserSearchResults results = new UserSearchResults();

            using (var context = new IdeaPoolEntities())
            {
                var query = context.Users.AsQueryable();
                if (!string.IsNullOrEmpty(searchsettings.SearchTerm))
                {
                    query = query.Where(user => user.FirstName.Contains(searchsettings.SearchTerm) ||
                                        user.LastName.Contains(searchsettings.SearchTerm));
                }
                results.TotalCount = query.Count();

                results.Results = query
                                  .OrderBy(user => user.FirstName)
                                  .Skip((searchsettings.CurrentPage - 1) * searchsettings.PageLength)
                                  .Take(searchsettings.PageLength)
                                  .Select(user => new UserBase
                {
                    Id                  = user.Id,
                    FirstName           = user.FirstName,
                    LastName            = user.LastName,
                    Company             = user.Company,
                    JoinedDate          = user.CreateDate,
                    TotalIdeasSubmitted = user.Ideas.Count
                })
                                  .ToList();
            }
            return(results);
        }
Beispiel #9
0
        public List <string> Update(SettingsGroupDataObject group)
        {
            List <string> keys = new List <string>();

            using (var context = new IdeaPoolEntities())
            {
                List <Setting> settings = context
                                          .SettingsGroups
                                          .Where(x => x.Key == group.Key)
                                          .Include(x => x.Settings)
                                          .SelectMany(x => x.Settings)
                                          .ToList();
                foreach (var setting in settings)
                {
                    SettingsDataObject obj = group.Settings.SingleOrDefault(x => x.Key == setting.Key);
                    if (obj != null && setting.Value != obj.Value)
                    {
                        setting.Value = obj.Value;
                        context.Entry(setting).State = EntityState.Modified;
                        keys.Add(setting.Key);
                    }
                }
                context.SaveChanges();
            }
            return(keys);
        }
Beispiel #10
0
 public List <KeyValuePair <int, string> > GetAllLabels()
 {
     using (var context = new IdeaPoolEntities())
     {
         List <FieldOfWater> fieldofwater = context.FieldOfWaters.Where(x => x.IsActive).ToList();
         return(fieldofwater.OrderBy(x => x.Order).Select(x => new KeyValuePair <int, string>(x.Id, x.Name)).ToList());
     }
 }
Beispiel #11
0
 public void Activate(int id)
 {
     using (var context = new IdeaPoolEntities())
     {
         IdeaStatus status = Get(context, id);
         status.IsActive = true;
         Update(context, status);
     }
 }
Beispiel #12
0
 public bool IsOwnerOrReviewer(int userId)
 {
     using (var context = new IdeaPoolEntities())
     {
         return(context.Users
                .Where(user => user.Id == userId && user.Roles.Any(role => role.Key == RoleKeys.OWNER || role.Key == RoleKeys.REVIEWER))
                .Any());
     }
 }
Beispiel #13
0
 public bool IsInDraftMode(int ideaId)
 {
     using (var context = new IdeaPoolEntities())
     {
         return(context.Ideas
                .Where(x => x.Id == ideaId && x.IdeaStatus.Key == IdeaStatusKeys.DRAFT)
                .Any());
     }
 }
Beispiel #14
0
 public string FetchStatusKey(int ideaId)
 {
     using (var context = new IdeaPoolEntities())
     {
         return(context.Ideas
                .Where(idea => idea.Id == ideaId)
                .Select(idea => idea.IdeaStatus.Key)
                .Single());
     }
 }
Beispiel #15
0
 public List <int> FetchAllIds(int ideaId)
 {
     using (var context = new IdeaPoolEntities())
     {
         return(context.IdeasFieldOfWaters
                .Where(x => x.IdeaId == ideaId)
                .Select(x => x.FieldOfWaterId)
                .ToList());
     }
 }
 public void ResetPassword(int userId, string password)
 {
     using (var context = new IdeaPoolEntities())
     {
         Login login = context.Logins.Where(x => x.UserId == userId).Single();
         login.Password             = password;
         context.Entry(login).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void ResetPassword(string token, string password)
 {
     using (var context = new IdeaPoolEntities())
     {
         Login login = context.ForgotPasswords.Where(x => x.Token == token).Select(x => x.User.Login).Single();
         login.Password             = password;
         context.Entry(login).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #18
0
 public List <KeyValueDataObject> FetchAllRoles()
 {
     using (var context = new IdeaPoolEntities())
     {
         return(context.Roles.Select(role => new KeyValueDataObject
         {
             Key = role.Key,
             Value = role.Name
         }).ToList());
     }
 }
Beispiel #19
0
 public bool TitleExists(int ideaId, string ideaName)
 {
     ideaName = ideaName.Trim().ToLower();
     using (var context = new IdeaPoolEntities())
     {
         return(context
                .Ideas
                .Where(x => x.Id != ideaId && x.Title.Trim().ToLower() == ideaName)
                .Count() > 0);
     }
 }
Beispiel #20
0
 private void UpdateFiles(IdeaPoolEntities context, List <FileDataObject> files, Idea ideaData)
 {
     foreach (File file in ideaData.Files.ToList())
     {
         if (!files.Any(x => x.Id == file.Id))
         {
             context.Files.Remove(file);
         }
     }
     fileData.Insert(context, files.Where(file => file.Id == 0).ToList(), ideaData.Id);
 }
Beispiel #21
0
 public bool DescriptionExists(int ideaId, string description)
 {
     description = description.Trim().ToLower();
     using (var context = new IdeaPoolEntities())
     {
         return(context
                .Ideas
                .Where(x => x.Id != ideaId && x.PlainContent.Trim().ToLower() == description)
                .Count() > 0);
     }
 }
 public void Delete(string token)
 {
     using (var context = new IdeaPoolEntities())
     {
         ForgotPassword passwordtoken = context.ForgotPasswords.SingleOrDefault(x => x.Token == token);
         if (passwordtoken != null)
         {
             context.Entry(passwordtoken).State = System.Data.Entity.EntityState.Deleted;
             context.SaveChanges();
         }
     }
 }
Beispiel #23
0
 public void InsertIdeaFieldOfWater(IdeaPoolEntities context, Idea ideaData, List <FieldOfWaterDataObject> fieldOfWaters)
 {
     foreach (var fieldofwater in fieldOfWaters)
     {
         context.IdeasFieldOfWaters.Add(new IdeasFieldOfWater
         {
             FieldOfWaterId = fieldofwater.Id,
             Description    = fieldofwater.Description,
             Idea           = ideaData
         });
     }
 }
Beispiel #24
0
        public string GetCreatorEmailAddress(int ideaId)
        {
            string email = string.Empty;

            using (var context = new IdeaPoolEntities())
            {
                email = context.Ideas.Where(x => x.Id == ideaId)
                        .Select(i => i.User.Email)
                        .SingleOrDefault();
            }
            return(email);
        }
Beispiel #25
0
 public void MarkRead(int ideaId, int userId)
 {
     using (var context = new IdeaPoolEntities())
     {
         UnReadDiscussion discussion = context.UnReadDiscussions.SingleOrDefault(x => x.IdeaId == ideaId && x.UserId == userId);
         if (discussion != null)
         {
             context.UnReadDiscussions.Remove(discussion);
             context.SaveChanges();
         }
     }
 }
Beispiel #26
0
 public void UpdateLoginDateTime(int userId)
 {
     using (var context = new IdeaPoolEntities())
     {
         Login login = context.Logins.SingleOrDefault(l => l.UserId == userId);
         if (login != null)
         {
             login.LastLogin            = DateTime.UtcNow;
             context.Entry(login).State = EntityState.Modified;
             context.SaveChanges();
         }
     }
 }
Beispiel #27
0
        public List <SettingsGroupDataObject> GetGroupSettings()
        {
            using (var context = new IdeaPoolEntities())
            {
                List <SettingsGroup> groups = context.SettingsGroups
                                              .Include(x => x.Settings)
                                              .ToList();

                return(groups
                       .Select(group => Map(group))
                       .ToList());
            }
        }
Beispiel #28
0
        public List <string> GetOwnerEmailAddresses()
        {
            List <string> emailAddresses = null;

            using (var context = new IdeaPoolEntities())
            {
                emailAddresses = context.Roles.Where(role => role.Key == RoleKeys.OWNER || role.Key == RoleKeys.REVIEWER)
                                 .SelectMany(x => x.Users)
                                 .Select(x => x.Email)
                                 .ToList();
            }
            return(emailAddresses);
        }
Beispiel #29
0
        private void InsertIdeaHistory(IdeaPoolEntities context, int ideaId, int userId, string activityKey, string description)
        {
            Activity ideaDetailsUpdate = context.Activities.Single(x => x.Key == activityKey);

            context.IdeaHistories.Add(new IdeaHistory
            {
                Activity    = ideaDetailsUpdate,
                IdeaId      = ideaId,
                UserId      = userId,
                Description = description,
                CreateDate  = DateTime.UtcNow
            });
        }
Beispiel #30
0
        public List <int> GetOwnerUserIds()
        {
            List <int> userIds = null;

            using (var context = new IdeaPoolEntities())
            {
                userIds = context.Roles.Where(role => role.Key == RoleKeys.OWNER || role.Key == RoleKeys.REVIEWER)
                          .SelectMany(x => x.Users)
                          .Select(x => x.Id)
                          .ToList();
            }
            return(userIds);
        }