public async Task <HttpResponseMessage> SaveSharedProjectAsync(SharedProjectsDto sharedProjectsDto)
        {
            var clientURL = RequestContext.Url.Request.Headers.GetValues("Origin").FirstOrDefault();
            var urlBrand  = "generac";

            if (clientURL.ToLower().Contains("pramac"))
            {
                urlBrand = "pramac";
            }
            if (String.IsNullOrEmpty(sharedProjectsDto.Language) || sharedProjectsDto.Language != "en" || sharedProjectsDto.Language != "en")
            {
                sharedProjectsDto.Language = "en";
            }

            var result = _userDashboard.SaveSharedProject(sharedProjectsDto, UserID, UserName);
            //var clientURL = RequestContext.Url.Request.Headers.GetValues("Origin").FirstOrDefault();
            var callbackURL = $"{clientURL}/project/{sharedProjectsDto.ProjectID}";

            var emaildata = new SendGridEmailData
            {
                template_id      = SectionHandler.GetSectionValue($"{sharedProjectsDto.Language.ToLower()}/emailTemplates/projectShared", "TemplateID", ""),
                personalizations = new List <Personalization>()
                {
                    new Personalization
                    {
                        to = new List <To>()
                        {
                            new To
                            {
                                email = sharedProjectsDto.RecipientEmail,
                                name  = sharedProjectsDto.RecipientEmail
                            }
                        },
                        substitutions = new Dictionary <string, string>()
                        {
                            { "%SharerLoginID%", UserName },
                            { "%ProjectName%", result.SharedProjectName },
                            { "%ProjectComments%", sharedProjectsDto.Notes },
                            { "%ProjectLink%", callbackURL },
                            { "%CompanyName%", EmailHelper.CompanyName(sharedProjectsDto.Language, urlBrand) },
                            { "%CompanyAddress%", EmailHelper.CompanyAddress(sharedProjectsDto.Language, urlBrand) }
                        }
                    }
                }
            };

            var emailResponse = EmailHelper.SendGridAsyncWithTemplate(emaildata);

            return(CreateHttpResponse(() =>
            {
                return Request.CreateResponse(result);
            }));
        }
Beispiel #2
0
        public SharedProjectsDto SaveSharedProject(SharedProjectsDto sharedProjectsDto, string userID, string userName)
        {
            //if (sharedProjectsDto.ID == 0)
            //{
            //    return AddSharedProjects(sharedProjectsDto, userID, userName);
            //}
            //else
            //{
            //    return new SharedProjectsDto
            //    {
            //        ID = 0,
            //    };
            //}

            return(AddSharedProjects(sharedProjectsDto, userID, userName));
        }
Beispiel #3
0
        private SharedProjectsDto AddSharedProjects(SharedProjectsDto sharedProjectsDto, string userID, string userName)
        {
            try
            {
                SharedProject sharedProjectDetails;
                SharedProject sharedProject = _sharedProjectsRepository.GetSingle(s => s.ProjectID == sharedProjectsDto.ProjectID && s.RecipientEmail.Equals(sharedProjectsDto.RecipientEmail, StringComparison.InvariantCultureIgnoreCase));
                if (sharedProject != null)
                {
                    foreach (var sharedSolutionID in sharedProjectsDto.SelectedSolutionList)
                    {
                        if (sharedProject.SharedProjectSolution.Where(s => s.SharedProjectID == sharedProject.ID && s.SolutionID == sharedSolutionID).Count() <= 0)
                        {
                            sharedProject.SharedProjectSolution.Add(new SharedProjectSolution
                            {
                                SharedProjectID  = sharedProject.ID,
                                SolutionID       = sharedSolutionID,
                                CreatedDateTime  = DateTime.UtcNow,
                                SharedDateTime   = DateTime.UtcNow,
                                ModifiedDateTime = DateTime.UtcNow,
                                CreatedBy        = userName,
                                ModifiedBy       = userName,
                                Active           = true
                            });
                        }
                        //else
                        //{
                        //    sharedProject.SharedProjectSolution.Remove(_sharedProjectSolutionRespository.GetSingle(s => s.SolutionID == sharedSolutionID));
                        //}
                    }
                    _sharedProjectsEntityToSharedProjectsDtoMapper.UpdateMap(sharedProjectsDto, sharedProject, userID);
                    sharedProject.ModifiedDateTime = DateTime.UtcNow;
                    sharedProject.ModifiedBy       = userName;
                    sharedProject.Active           = true;

                    sharedProjectDetails = _sharedProjectsRepository.Update(sharedProject);
                    _sharedProjectsRepository.Commit();
                }
                else
                {
                    sharedProject = _sharedProjectsEntityToSharedProjectsDtoMapper.AddMap(sharedProjectsDto, userID);
                    sharedProject.CreatedDateTime  = DateTime.UtcNow;
                    sharedProject.CreatedBy        = userName;
                    sharedProject.SharedDateTime   = DateTime.UtcNow;
                    sharedProject.ModifiedDateTime = DateTime.UtcNow;
                    sharedProject.ModifiedBy       = userName;
                    sharedProject.Active           = true;

                    sharedProject.SharedProjectSolution = sharedProjectsDto.SelectedSolutionList.Select(solutionID => new SharedProjectSolution
                    {
                        SolutionID       = solutionID,
                        CreatedDateTime  = DateTime.UtcNow,
                        SharedDateTime   = DateTime.UtcNow,
                        ModifiedDateTime = DateTime.UtcNow,
                        CreatedBy        = userName,
                        ModifiedBy       = userName,
                        Active           = true
                    }).ToList();

                    sharedProjectDetails = _sharedProjectsRepository.Add(sharedProject);
                    _sharedProjectsRepository.Commit();
                }

                Project sharedProjectRow  = _projectRepository.GetSingle(p => p.ID == sharedProjectsDto.ProjectID);
                var     sharedProjectName = sharedProjectRow.ProjectName;
                var     sharerUserName    = sharedProjectRow.User.FirstName + " " + sharedProjectRow.User.LastName;

                return(new SharedProjectsDto
                {
                    SharedProjectID = sharedProjectDetails.ID,
                    SharedProjectName = sharedProjectName,
                    SharerUserName = sharerUserName
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }