예제 #1
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);
        }
예제 #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);
            }
        }
예제 #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());
        }
예제 #4
0
 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();
     }
 }
예제 #5
0
 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();
     }
 }
예제 #6
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();
         }
     }
 }
예제 #7
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();
         }
     }
 }
예제 #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();
     }
 }
예제 #9
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();
     }
 }
예제 #10
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);
        }
예제 #11
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);
        }
예제 #12
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);
        }
예제 #13
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);
        }
예제 #14
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();
     }
 }
예제 #15
0
 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();
     }
 }
예제 #16
0
 private void Update(IdeaPoolEntities context, IdeaStatus status)
 {
     context.Entry(status).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }