Exemplo n.º 1
0
        public void InsertIdeaTest_OK()
        {
            RESTAPIIdeaController apiController = new RESTAPIIdeaController()
            {
                DeviceWithDbContext = new RESTAPIDeviceWithDbContext()
                {
                    DbContext = new IdeaDatabase.DataContext.IdeaDatabaseDataContext()
                }
            };

            RestAPISubmitIdeaResponse response = new RestAPISubmitIdeaResponse()
            {
                ErrorList = new HashSet <Fault>()
                {
                    new Fault("Submit Idea", "", "")
                }
            };

            RestAPISubmitIdeaRequest request = new RestAPISubmitIdeaRequest()
            {
                Title            = "test",
                BusinessImpact   = "test",
                CategoryId       = 1,
                ChallengeId      = 1,
                Description      = "test",
                IdeaContributors = "test",
                IsDraft          = false,
                Solution         = "test"
            };

            ideaMock.Setup(x => x.SubmitIdeas(It.IsAny <RestAPISubmitIdeaResponse>(), It.IsAny <RestAPISubmitIdeaRequest>(), It.IsAny <int>())).Returns(response);
            response = apiController.InsertIdea(request);

            Assert.IsTrue(response.ErrorList.Count == 0);
        }
        public RestAPISubmitIdeaResponse InsertIdea(RestAPISubmitIdeaRequest req)
        {
            RestAPISubmitIdeaResponse response = new RestAPISubmitIdeaResponse();

            ideaUtil.SubmitIdeas(response, req, UserID);

            return(response);
        }
        public void SubmitIdeasTest()
        {
            IdeaUtil ideaUtil = new IdeaUtil();
            int      UserId   = 1;
            RestAPISubmitIdeaResponse response = new RestAPISubmitIdeaResponse();
            RestAPISubmitIdeaRequest  request  = new RestAPISubmitIdeaRequest()
            {
                Title            = "test",
                BusinessImpact   = "test",
                CategoryId       = 1,
                ChallengeId      = 54,
                Description      = "test",
                IdeaContributors = "test",
                IsDraft          = true,
                Solution         = "test"
            };

            ideaMock.Setup(x => x.SubmitIdeas(It.IsAny <RestAPISubmitIdeaResponse>(), It.IsAny <RestAPISubmitIdeaRequest>(), It.IsAny <int>())).Returns(response);
            response = ideaUtil.SubmitIdeas(response, request, UserId);

            Assert.IsTrue(response.ErrorList.Count == 0);
        }
        public RestAPISubmitIdeaResponse SubmitIdeas(RestAPISubmitIdeaResponse response, RestAPISubmitIdeaRequest req, int UserID)
        {
            try
            {
                ideautils.SubmitIdeaRequest(response, req, UserID);

                if (response.ErrorList.Count != 0)
                {
                    return(response);
                }

                if (!req.IsDraft)
                {
                    // Submit IdeaAssignment and Send email if Idea is not drafted
                    ideautils.SubmitIdeaAssignment(response, response.IdeaId);
                    SendEmail(response.IdeaId);
                }

                if (response.ErrorList.Count != 0)
                {
                    return(response);
                }

                if (response.ErrorList.Count != 0)
                {
                    response.Status = Failure;
                }
            }
            catch (Exception ex)
            {
                response.Status = Failure;
                throw new Exception(ex.Message, ex);
            }

            return(response);
        }
        public void SubmitIdeaRequest(RestAPISubmitIdeaResponse response, SubmitIdeaRequest submitIdeaRequest, int UserId)
        {
            DatabaseWrapper.databaseOperation(response,
                                              (context, query) =>
            {
                Idea idea                   = new Idea();
                IdeaCategory category       = query.GetIdeaFromCategoryID(context, submitIdeaRequest.CategoryId);
                IdeaChallenge ideaChallenge = query.GetChallengeByID(context, submitIdeaRequest.ChallengeId);

                // insert category
                if (category != null)
                {
                    idea.IdeaCategory = category;
                }

                //insert challenge
                if (ideaChallenge != null)
                {
                    idea.ChallengeId = ideaChallenge.IdeaChallengeId;
                }

                //insert Ideacontributors
                if (!string.IsNullOrEmpty(submitIdeaRequest.IdeaContributors))
                {
                    List <string> contributors = GetContributorList(submitIdeaRequest.IdeaContributors);
                    List <User> userList       = query.GetUserByNames(context, contributors);

                    foreach (var user in userList)
                    {
                        idea.IdeaContributors.Add(new IdeaContributor()
                        {
                            IdeaId = idea.IdeaId, UserId = user.UserId, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow
                        });
                    }
                }

                //insert idea status
                IdeaStatusLog ideaStatusLog = new IdeaStatusLog()
                {
                    CreatedDate      = DateTime.UtcNow,
                    ModifiedByUserId = UserId,
                    IsActive         = true,
                    IdeaState        = submitIdeaRequest.IsDraft ? (int)IdeaStatusTypes.SubmitPending : (int)IdeaStatusTypes.ReviewPending
                };

                idea.IdeaStatusLogs.Add(ideaStatusLog);

                idea.Title          = submitIdeaRequest.Title;
                idea.Description    = submitIdeaRequest.Description;
                idea.IsActive       = true;
                idea.CreatedDate    = DateTime.UtcNow;
                idea.ModifiedDate   = DateTime.UtcNow;
                idea.BusinessImpact = submitIdeaRequest.BusinessImpact;
                idea.UserId         = UserId;
                idea.IsSensitive    = true;
                idea.Solution       = submitIdeaRequest.Solution;
                idea.IsDraft        = submitIdeaRequest.IsDraft;

                query.AddIdea(context, idea);
                context.SubmitChanges();
                response.IdeaId = idea.IdeaId;
                response.Status = Success;
            }
                                              , readOnly: false
                                              );

            if (response.ErrorList.Count != 0)
            {
                response.ErrorList.Add(Faults.ServerIsBusy);
            }
        }