Beispiel #1
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 #2
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 #3
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);
        }
 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();
     }
 }
 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 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 #7
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 #8
0
 public void Activate(int fieldOfWaterId)
 {
     using (var context = new IdeaPoolEntities())
     {
         FieldOfWater fieldOfWater = context
                                     .FieldOfWaters
                                     .Where(x => x.Id == fieldOfWaterId)
                                     .Single();
         fieldOfWater.IsActive             = true;
         context.Entry(fieldOfWater).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #9
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 #10
0
 public void Update(UserDataObject user)
 {
     using (var context = new IdeaPoolEntities())
     {
         User entity = context.Users.Where(x => x.Id == user.Id).Single();
         entity.FirstName             = user.FirstName;
         entity.LastName              = user.LastName;
         entity.Company               = user.Company;
         entity.Phone                 = user.Phone;
         entity.IsSubscriptionEnabled = user.IsSubscriptionEnabled;
         context.Entry(entity).State  = EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #11
0
 public void InsertMessage(int ideaId, int userId, string message)
 {
     using (var context = new IdeaPoolEntities())
     {
         Discussion discussion = new Discussion
         {
             IdeaId     = ideaId,
             UserId     = userId,
             Message    = message,
             CreateDate = DateTime.UtcNow
         };
         context.Discussions.Add(discussion);
         context.SaveChanges();
     }
 }
Beispiel #12
0
 public void InsertFile(int ideaId, int userId, int fileId)
 {
     using (var context = new IdeaPoolEntities())
     {
         Discussion discussion = new Discussion
         {
             IdeaId     = ideaId,
             UserId     = userId,
             FileId     = fileId,
             CreateDate = DateTime.UtcNow
         };
         context.Discussions.Add(discussion);
         context.SaveChanges();
     }
 }
Beispiel #13
0
        public int Add(UserDataObject userDataObject)
        {
            int userId = 0;

            using (var context = new IdeaPoolEntities())
            {
                User user = new User
                {
                    FirstName             = userDataObject.FirstName,
                    LastName              = userDataObject.LastName,
                    Company               = userDataObject.Company,
                    Email                 = userDataObject.Email,
                    Phone                 = userDataObject.Phone,
                    CreateDate            = DateTime.UtcNow,
                    IsSubscriptionEnabled = userDataObject.IsSubscriptionEnabled,
                    IsActive              = true
                };
                Role submitterRole = context.Roles.Single(x => x.Key == RoleKeys.SUBMITTER);

                // Add submitter role
                user.Roles.Add(submitterRole);
                context.Users.Add(user);
                context.SaveChanges();

                Login login = new Login
                {
                    UserId      = user.Id,
                    Password    = userDataObject.EncryptedPassword,
                    IsActivated = false
                };
                context.Logins.Add(login);
                context.SaveChanges();
                userId = user.Id;
            }
            return(userId);
        }
Beispiel #14
0
        public bool UpdateLoginStatus(int userId, bool status)
        {
            bool saved = false;

            using (var context = new IdeaPoolEntities())
            {
                Login login = context.Logins.Where(x => x.UserId == userId).SingleOrDefault();
                if (login != null)
                {
                    login.IsActivated          = status;
                    context.Entry(login).State = EntityState.Modified;
                    context.SaveChanges();
                    saved = true;
                }
            }
            return(saved);
        }
Beispiel #15
0
        public bool UpdateAccountStatus(int userid, bool status)
        {
            bool saved = false;

            using (var context = new IdeaPoolEntities())
            {
                User usr = context.Users.Where(user => user.Id == userid).SingleOrDefault();
                if (usr != null)
                {
                    usr.IsActive             = status;
                    context.Entry(usr).State = EntityState.Modified;
                    context.SaveChanges();
                    saved = true;
                }
            }
            return(saved);
        }
Beispiel #16
0
 public void Insert(AuditDataObject audit)
 {
     using (var context = new IdeaPoolEntities())
     {
         AuditType type = context.AuditTypes.Where(x => x.Key == audit.AuditTypeKey).Single();
         context.Audits.Add(new Audit
         {
             AuditType    = type,
             CreateDate   = DateTime.UtcNow,
             Description  = audit.Description,
             IdeaId       = audit.IdeaId,
             LoginUserId  = audit.LoginUserId,
             UpdateUserId = audit.UpdateUserId
         });
         context.SaveChanges();
     }
 }
Beispiel #17
0
        public bool Activate(string email)
        {
            bool isActivated = false;

            using (var context = new IdeaPoolEntities())
            {
                Login login = context.Users.Where(user => user.Email == email).Select(u => u.Login).SingleOrDefault();
                if (login != null)
                {
                    login.IsActivated          = true;
                    isActivated                = true;
                    context.Entry(login).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
            return(isActivated);
        }
Beispiel #18
0
 public void Insert(IdeaStatusDataObject status)
 {
     using (var context = new IdeaPoolEntities())
     {
         context.IdeaStatus.Add(new IdeaStatus
         {
             Color           = status.Color,
             CreatedByUserId = status.CreatedByUserId,
             Description     = status.Description,
             Status          = status.Name,
             IsActive        = true,
             IsVisible       = true,
             Key             = status.Name.Replace(" ", "").ToUpper()
         });
         context.SaveChanges();
     }
 }
Beispiel #19
0
 public void Insert(ExceptionDataObject exceptionObject)
 {
     using (var context = new IdeaPoolEntities())
     {
         Exception exception = new Exception
         {
             Message       = exceptionObject.Message,
             CallStack     = exceptionObject.CallStack,
             CreatedDate   = DateTime.UtcNow,
             ExceptionType = exceptionObject.ExceptionType,
             UserId        = exceptionObject.UserId,
             UserAgent     = exceptionObject.UserAgent
         };
         context.Exceptions.Add(exception);
         context.SaveChanges();
     }
 }
Beispiel #20
0
 public void MarkUnread(int ideaId, List <int> userIds)
 {
     using (var context = new IdeaPoolEntities())
     {
         foreach (int userid in userIds)
         {
             if (!context.UnReadDiscussions.Any(x => x.UserId == userid && x.IdeaId == ideaId))
             {
                 UnReadDiscussion unread = new UnReadDiscussion
                 {
                     IdeaId = ideaId,
                     UserId = userid
                 };
                 context.UnReadDiscussions.Add(unread);
             }
         }
         context.SaveChanges();
     }
 }
Beispiel #21
0
        public bool UpdateStatus(int ideaId, int statusId, int userId)
        {
            bool isUpdate = false;

            using (var context = new IdeaPoolEntities())
            {
                Idea       idea   = context.Ideas.SingleOrDefault(x => x.Id == ideaId);
                IdeaStatus status = context.IdeaStatus.SingleOrDefault(x => x.Id == statusId);
                if (idea != null && status != null)
                {
                    idea.IdeaStatus           = status;
                    context.Entry(idea).State = EntityState.Modified;
                    InsertIdeaHistory(context, ideaId, userId, ActivityKeys.UPDATE_IDEA_STATUS, status.Status);
                    context.SaveChanges();
                    isUpdate = true;
                }
            }
            return(isUpdate);
        }
Beispiel #22
0
 public void Insert(FieldOfWaterDataObject fieldOfWater)
 {
     using (var context = new IdeaPoolEntities())
     {
         FieldOfWater other = context.FieldOfWaters.Where(x => x.Id == FIELDOFWATER_OTHER_ID).Single();
         context
         .FieldOfWaters
         .Add(new FieldOfWater
         {
             CreatedByUserId = fieldOfWater.CreatedByUserId,
             Name            = fieldOfWater.Name,
             Description     = fieldOfWater.Description,
             IsActive        = true,
             Order           = other.Order // set the order to last but one
         });
         // Increment the order of other field of water to last
         other.Order = other.Order + 1;
         context.Entry(other).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #23
0
        public int Insert(FileDataObject file, int ideaId)
        {
            int fileId;

            using (var context = new IdeaPoolEntities())
            {
                File dbFile = new File
                {
                    Content     = file.Content,
                    ContentType = file.ContentType,
                    IdeaId      = ideaId,
                    Name        = file.Name,
                    Thumbnail   = file.Thumbnail,
                    SizeInKb    = file.SizeInKb,
                    UniqueID    = Guid.NewGuid(),
                    IsUploadedViaDiscussions = file.IsUploadedViaDiscussions
                };
                context.Files.Add(dbFile);
                context.SaveChanges();
                fileId = dbFile.Id;
            }
            return(fileId);
        }
 public void InsertOrUpdate(int userId, string token)
 {
     using (var context = new IdeaPoolEntities())
     {
         ForgotPassword forgotpassword = context.ForgotPasswords.SingleOrDefault(x => x.UserId == userId);
         if (forgotpassword == null)
         {
             context.ForgotPasswords.Add(new ForgotPassword
             {
                 UserId         = userId,
                 Token          = token,
                 ExpiryDateTime = DateTime.UtcNow.AddDays(1)
             });
         }
         else
         {
             forgotpassword.Token                = token;
             forgotpassword.ExpiryDateTime       = DateTime.UtcNow.AddDays(1);
             context.Entry(forgotpassword).State = System.Data.Entity.EntityState.Modified;
         }
         context.SaveChanges();
     }
 }
Beispiel #25
0
        public List <KeyValueDataObject> RemoveRole(int userId, string key)
        {
            List <KeyValueDataObject> roles = new List <KeyValueDataObject>();

            using (var context = new IdeaPoolEntities())
            {
                User user = context.Users
                            .Include(x => x.Roles)
                            .Where(x => x.Id == userId)
                            .SingleOrDefault();
                if (user != null)
                {
                    Role role = context.Roles.Where(x => x.Key == key).SingleOrDefault();
                    if (role != null)
                    {
                        user.Roles.Remove(role);
                        context.SaveChanges();
                    }
                    roles = GetRoles(user);
                }
            }
            return(roles);
        }
Beispiel #26
0
 private void Update(IdeaPoolEntities context, IdeaStatus status)
 {
     context.Entry(status).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }