Ejemplo n.º 1
0
        public int Update(IdeaDataObject idea)
        {
            if (idea.Id == 0)
            {
                throw new CustomException("Cannot update Idea details.");
            }
            int userId = ideaData.GetCreatorUserId(idea.Id);

            if (idea.UserId != userId)
            {
                throw new PermissionException();
            }
            string statusKey = ideaData.FetchStatusKey(idea.Id);

            if (statusKey != IdeaStatusKeys.DRAFT && statusKey != IdeaStatusKeys.SUBMITTED)
            {
                throw new CustomException("Error: Idea with submitted status can only be updated.");
            }
            IdeaValidator validator = new IdeaValidator(settingsData.GetGroupSettings(SettingsKeys.IdeaForm.GroupKEY));

            if (!validator.IsValid(idea))
            {
                throw new FormException(validator.ErrorCodes);
            }
            foreach (var file in idea.Files.Where(file => file.Id == 0))
            {
                file.Thumbnail = fileProcess.GetThumbnail(file);
            }
            int id = ideaData.Update(idea);

            return(id);
        }
Ejemplo n.º 2
0
        public void ErrorCodes_should_be_populated_when_fieldOfwater_is_not_selected()
        {
            IdeaDataObject idea = new IdeaDataObject();

            validator.IsValid(idea);
            Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.IdeaForm.ERROR_IDEAFORM_FIELDOFWATER_REQUIRED));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void ErrorCodes_should_not_be_populated_when_all_the_values_are_with_in_the_configured_range()
        {
            IdeaDataObject idea = new IdeaDataObject()
            {
                Title        = "Some title",
                Description  = "Description",
                FieldOfWater = new List <FieldOfWaterDataObject>
                {
                    new FieldOfWaterDataObject {
                        Id = 1
                    },
                    new FieldOfWaterDataObject {
                        Id = 2
                    },
                    new FieldOfWaterDataObject {
                        Id = -1, Description = "Some other text"
                    }
                },
                Files = new List <FileDataObject>
                {
                    new FileDataObject
                    {
                        Content = new byte[1048576]
                    }
                }
            };

            validator.IsValid(idea);
            Assert.IsTrue(validator.ErrorCodes.Count == 0);
        }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
        public void Save_should_not_throw_exception_when_all_the_values_are_with_in_the_configured_range()
        {
            IdeaDataObject idea = new IdeaDataObject()
            {
                Title        = "Some title",
                Description  = "Description",
                FieldOfWater = new List <FieldOfWaterDataObject>
                {
                    new FieldOfWaterDataObject {
                        Id = 1
                    },
                    new FieldOfWaterDataObject {
                        Id = 2
                    },
                    new FieldOfWaterDataObject {
                        Id = -1, Description = "Some other text"
                    }
                },
                Files = new List <FileDataObject>
                {
                    new FileDataObject
                    {
                        Content = new byte[1048576]
                    }
                }
            };

            process.Save(idea);
            ideasData.Verify(x => x.Insert(It.IsAny <IdeaDataObject>()));
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public void ErrorCodes_should_be_populated_when_description_is_empty()
        {
            IdeaDataObject idea = new IdeaDataObject();

            validator.IsValid(idea);
            Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.IdeaForm.ERROR_IDEAFORM_DESCRIPTION_REQUIRED));
        }
Ejemplo n.º 9
0
 public bool IsValid(IdeaDataObject idea)
 {
     validateTitle(idea.Title);
     validateFieldOfWater(idea);
     validateDescription(idea.Description);
     validateFiles(idea.Files);
     return(ErrorCodes.Count == 0);
 }
Ejemplo n.º 10
0
        public void ErrorCodes_should_be_populated_when_title_exceeds_the_settings_length()
        {
            IdeaDataObject idea = new IdeaDataObject();

            idea.Title = "Title is greater than the configured length. Title is greater than the configured length.Title is greater than the configured length.";
            validator.IsValid(idea);
            Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.IdeaForm.ERROR_IDEAFORM_TITLE_LENGTH));
        }
Ejemplo n.º 11
0
        private IdeaDataObject MapIdea(Idea idea, FetchMode mode)
        {
            IdeaDataObject ideaData = null;

            if (idea != null)
            {
                ideaData = new IdeaDataObject
                {
                    Id       = idea.Id,
                    UniqueId = idea.UniqueId,
                    UserId   = idea.UserId,
                    User     = new UserNameObject
                    {
                        Id        = idea.User.Id,
                        FirstName = idea.User.FirstName,
                        LastName  = idea.User.LastName
                    },
                    IsDraft = idea.IsDraft
                };

                if (mode == FetchMode.Full)
                {
                    ideaData.Title           = idea.Title;
                    ideaData.DescriptionHtml = idea.HtmlContent;
                    ideaData.CreateDate      = idea.CreatedDate.ToLocalTime();
                    idea.Files.ToList().ForEach(file =>
                    {
                        ideaData.Files.Add(new FileDataObject
                        {
                            ThumbnailBase64 = Convert.ToBase64String(file.Thumbnail),
                            ContentType     = file.ContentType,
                            Id       = file.Id,
                            Name     = file.Name,
                            SizeInKb = file.SizeInKb,
                            IsUploadedViaDiscussions = file.IsUploadedViaDiscussions
                        });
                    });
                    idea.IdeasFieldOfWaters.ToList().ForEach(fieldofWater =>
                    {
                        ideaData.FieldOfWater.Add(new FieldOfWaterDataObject
                        {
                            Name        = fieldofWater.FieldOfWater.Name,
                            Description = fieldofWater.Description,
                            Id          = fieldofWater.FieldOfWater.Id
                        });
                    });
                    ideaData.Status = new IdeaStatusDataObject
                    {
                        Id    = idea.IdeaStatus.Id,
                        Name  = idea.IdeaStatus.Status,
                        Color = idea.IdeaStatus.Color,
                        IsInSubmittedStatus = idea.IdeaStatus.Key == IdeaStatusKeys.SUBMITTED
                    };
                }
            }
            return(ideaData);
        }
Ejemplo n.º 12
0
        public IdeaDataObject Fetch(int ideaId, FetchMode mode)
        {
            IdeaDataObject idea = ideaData.Fetch(ideaId, mode);

            if (idea == null)
            {
                throw new CustomException("Unable to fetch Idea details.");
            }
            return(idea);
        }
Ejemplo n.º 13
0
 private void validateFieldOfWater(IdeaDataObject idea)
 {
     if (idea.FieldOfWater.Count == 0)
     {
         ErrorCodes.Add(ErrorConstants.IdeaForm.ERROR_IDEAFORM_FIELDOFWATER_REQUIRED);
     }
     else if (idea.FieldOfWater.Find(x => x.Id == -1) != null && string.IsNullOrEmpty(idea.FieldOfWater.Find(x => x.Id == -1).Description))
     {
         ErrorCodes.Add(ErrorConstants.IdeaForm.ERROR_IDEAFORM_FIELDOFWATER_OTHER_REQUIRED);
     }
 }
Ejemplo n.º 14
0
        public void Save(IdeaDataObject idea)
        {
            idea.Files.AddRange(FetchUploadedFiles());
            idea.UserId = UserId;
            int id = ProcessFactory.GetIdeaProcess().Save(idea);

            if (!idea.IsDraft)
            {
                NotifyOwners(id);
            }
        }
Ejemplo n.º 15
0
        public JsonResult FetchIdeaDetails(int id)
        {
            IIdeaProcess ideaprocess = ProcessFactory.GetIdeaProcess();

            if (ideaprocess.GetCreatorUserId(id) != UserId && !HasAccess(FeatureAccess.VIEW_IDEAS_OF_OTHERS))
            {
                throw new PermissionException();
            }
            IdeaDataObject idea = ideaprocess.Fetch(id, FetchMode.Full);

            return(Json(idea, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 16
0
        public void ErrorCodes_should_be_populated_when_number_of_files_exceeds_the_configuted_length()
        {
            IdeaDataObject idea = new IdeaDataObject();

            idea.Files = new List <FileDataObject>
            {
                new FileDataObject(),
                new FileDataObject(),
                new FileDataObject()
            };
            validator.IsValid(idea);
            Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.IdeaForm.ERROR_IDEAFORM_FILE_LIMIT));
        }
Ejemplo n.º 17
0
        public void ErrorCodes_should_be_populated_when_Other_fieldofwater_is_selected_and_text_is_empty()
        {
            IdeaDataObject idea = new IdeaDataObject();

            idea.FieldOfWater = new List <FieldOfWaterDataObject>
            {
                new FieldOfWaterDataObject
                {
                    Id = -1
                }
            };
            validator.IsValid(idea);
            Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.IdeaForm.ERROR_IDEAFORM_FIELDOFWATER_OTHER_REQUIRED));
        }
Ejemplo n.º 18
0
        public int Save(IdeaDataObject idea)
        {
            IdeaValidator validator = new IdeaValidator(settingsData.GetGroupSettings(SettingsKeys.IdeaForm.GroupKEY));

            if (!validator.IsValid(idea))
            {
                throw new FormException(validator.ErrorCodes);
            }

            foreach (var file in idea.Files)
            {
                file.Thumbnail = fileProcess.GetThumbnail(file);
            }

            return(ideaData.Insert(idea));
        }
Ejemplo n.º 19
0
        private List <IdeaDataObject> MapIdeas(List <Idea> ideas, int currentUserId)
        {
            List <IdeaDataObject> ideasData = new List <IdeaDataObject>();

            ideas.ForEach(idea =>
            {
                IdeaDataObject ideaData = new IdeaDataObject
                {
                    Id           = idea.Id,
                    CreateDate   = idea.CreatedDate.ToLocalTime(),
                    Title        = idea.Title,
                    FieldOfWater = idea.IdeasFieldOfWaters.Select(x =>
                    {
                        FieldOfWaterDataObject fieldofwater = null;
                        if (x.FieldOfWaterId == FIELDOFWATER_OTHER_ID)
                        {
                            fieldofwater = new FieldOfWaterDataObject {
                                Name = x.Description
                            };
                        }
                        else
                        {
                            fieldofwater = new FieldOfWaterDataObject {
                                Name = x.FieldOfWater.Name
                            };
                        }
                        return(fieldofwater);
                    }).ToList(),
                    Status = new IdeaStatusDataObject
                    {
                        Name  = idea.IdeaStatus.Status,
                        Color = idea.IdeaStatus.Color,
                        IsInSubmittedStatus = idea.IdeaStatus.Key == IdeaStatusKeys.SUBMITTED
                    },
                    User = new UserNameObject
                    {
                        FirstName = idea.User.FirstName,
                        LastName  = idea.User.LastName
                    },
                    UserId = idea.User.Id,
                    HasUnreadDiscussions = idea.UnReadDiscussions.Any(d => d.UserId == currentUserId),
                    IsDraft = idea.IsDraft
                };
                ideasData.Add(ideaData);
            });
            return(ideasData);
        }
Ejemplo n.º 20
0
        public void IdeaUpdated(int ideaId, string updateReason, string url)
        {
            IdeaDataObject   idea = DataFactory.GetIdeaData().Fetch(ideaId, FetchMode.LightWeight);
            List <string>    emailAddressesOfOwners = ProcessFactory.GetUserProcess().GetOwnerEmailAddresses();
            IdeaUpdatedModel model = new IdeaUpdatedModel
            {
                Url       = url,
                Reason    = updateReason,
                FirstName = idea.User.FirstName,
                LastName  = idea.User.LastName
            };
            EmailSettings settings = MapSettings(mailSettings);

            settings.Subject = "Idea updated";
            settings.Tos     = emailAddressesOfOwners;
            SendEmail(settings, "IdeaUpdated", model);
        }
Ejemplo n.º 21
0
        public void Save_should_throw_exception_when_fieldofwater_is_not_selected()
        {
            IdeaDataObject idea = new IdeaDataObject
            {
                Title        = "Title",
                Description  = "Description",
                FieldOfWater = new List <FieldOfWaterDataObject>(),
                Files        = new List <FileDataObject>
                {
                    new FileDataObject
                    {
                        Content = new byte[100]
                    }
                }
            };

            process.Save(idea);
        }
Ejemplo n.º 22
0
        public void IdeaCreated(string url, int ideaId)
        {
            IdeaDataObject idea                   = DataFactory.GetIdeaData().Fetch(ideaId, FetchMode.LightWeight);
            string         creatorEmail           = ProcessFactory.GetIdeaProcess().GetCreatorEmailAddress(ideaId);
            List <string>  emailAddressesOfOwners = ProcessFactory.GetUserProcess().GetOwnerEmailAddresses();

            emailAddressesOfOwners.Remove(creatorEmail);
            IdeaSubmittedModel model = new IdeaSubmittedModel
            {
                CreatedBy   = string.Format("{0}, {1}", idea.User.FirstName, idea.User.LastName),
                ViewIdeaUrl = url
            };
            EmailSettings settings = MapSettings(mailSettings);

            settings.Subject = "New Idea submitted";
            settings.Tos     = emailAddressesOfOwners;
            SendEmail(settings, "IdeaCreated", model);
        }
Ejemplo n.º 23
0
 private object MapForDisplay(IdeaDataObject idea, bool hasAccessToOthersIdeas)
 {
     return(new
     {
         idea.Id,
         SubmitDate = idea.CreateDate.ToShortDateString(),
         idea.Title,
         FieldOdWater = idea.FieldOfWater.Select(x => x.Name),
         Status = new
         {
             idea.Status.Name,
             idea.Status.Color
         },
         CreatedBy = hasAccessToOthersIdeas ? string.Format("{0}, {1}", idea.User.FirstName, idea.User.LastName) : string.Empty,
         CanEdit = idea.UserId == UserId && (idea.Status.IsInSubmittedStatus || idea.IsDraft),
         idea.HasUnreadDiscussions,
         idea.IsDraft
     });
 }
Ejemplo n.º 24
0
        public void Update(IdeaDataObject idea)
        {
            idea.Files.AddRange(FetchUploadedFiles());
            idea.UserId = UserId;
            IIdeaProcess process = ProcessFactory.GetIdeaProcess();
            bool         isInDraftModeBeforeUpdate = process.IsInDraftMode(idea.Id);
            int          id = process.Update(idea);

            if (!idea.IsDraft)
            {
                if (isInDraftModeBeforeUpdate)
                {
                    NotifyOwners(id);
                }
                else
                {
                    NotifyIdeaUpdate(id, idea.Reason);
                }
            }
        }
Ejemplo n.º 25
0
        public void ErrorCodes_should_be_populated_when_description_exceeds_the_settings_length()
        {
            IdeaDataObject idea = new IdeaDataObject();

            idea.Description = @"Description is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured length. Description is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured lengthDescription is greater than the configured length. Description is greater than the configured length.Description is 
                greater than the configured length";
            validator.IsValid(idea);
            Assert.IsTrue(validator.ErrorCodes.Contains(ErrorCodes.IdeaForm.ERROR_IDEAFORM_DESCRIPTION_LENGTH));
        }
Ejemplo n.º 26
0
        public void Save_Should_throw_exception_when_number_of_files_exceeds_the_configuted_length()
        {
            IdeaDataObject idea = new IdeaDataObject
            {
                Title        = "Title",
                Description  = "Description",
                FieldOfWater = new List <FieldOfWaterDataObject>
                {
                    new FieldOfWaterDataObject
                    {
                        Id = 1
                    }
                },
                Files = new List <FileDataObject>
                {
                    new FileDataObject(),
                    new FileDataObject(),
                    new FileDataObject()
                }
            };

            process.Save(idea);
        }
Ejemplo n.º 27
0
        public void Save_should_throw_exception_when_title_is_Empty()
        {
            IdeaDataObject idea = new IdeaDataObject
            {
                Title        = string.Empty,
                Description  = "Description",
                FieldOfWater = new List <FieldOfWaterDataObject>
                {
                    new FieldOfWaterDataObject
                    {
                        Id = -1
                    }
                },
                Files = new List <FileDataObject>
                {
                    new FileDataObject
                    {
                        Content = new byte[100]
                    }
                }
            };

            process.Save(idea);
        }
Ejemplo n.º 28
0
        public void Save_should_throw_exception_when_file_size_exceeds_the_configuted_length()
        {
            IdeaDataObject idea = new IdeaDataObject
            {
                Title        = "Title",
                Description  = "Description",
                FieldOfWater = new List <FieldOfWaterDataObject>
                {
                    new FieldOfWaterDataObject
                    {
                        Id = 1
                    }
                },
                Files = new List <FileDataObject>
                {
                    new FileDataObject
                    {
                        Content = new byte[3145728]
                    }
                }
            };

            process.Save(idea);
        }
Ejemplo n.º 29
0
        public void Save_should_throw_exception_when_title_exceeds_configured_length()
        {
            IdeaDataObject idea = new IdeaDataObject
            {
                Title        = "Title is greater than the configured length. Title is greater than the configured length.Title is greater than the configured length.",
                Description  = "Description",
                FieldOfWater = new List <FieldOfWaterDataObject>
                {
                    new FieldOfWaterDataObject
                    {
                        Id = 1
                    }
                },
                Files = new List <FileDataObject>
                {
                    new FileDataObject
                    {
                        Content = new byte[100]
                    }
                }
            };

            process.Save(idea);
        }