コード例 #1
0
        public static LmpPrincipal Convertuser()
        {
            string contextuser = HttpContext.Current.User.Identity.Name;// HttpContext.User.Identity.Name;

            string[] splituser = AMPUtilities.SplitLoginName(contextuser);
            string   username  = splituser[0];

            if (splituser.Length > 1)
            {
                username = splituser[1];
            }
            using (AMPEntities context = new AMPEntities())
            {
                var user = context.TBL_Users.Where(us => string.Compare(username, us.Username, StringComparison.OrdinalIgnoreCase) == 0).FirstOrDefault();
                if (user != null)
                {
                    return(new LmpPrincipal(user));
                }
                else
                {
                    return(new LmpPrincipal(new TBL_Users()
                    {
                        ContactId = 0,
                        Department = "Guest",
                        DisplayName = "Guest",
                        EmailAddress = "",
                        EmployeeNo = "",
                        Username = "******",
                        TBL_Contacts = new TBL_Contacts()
                    }
                                            ));
                }
            }
        }
コード例 #2
0
        public async Task <ProjectApprovedBudget> GetProjectApprovedBudgetAsync(string projectID, string user) //Rename this
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(AMPUtilities.FinanceWebServiceUrl());                                // We should store this in the web.config file
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // This probably removes the need to have the config in the API

                try
                {
                    // HTTP GET
                    HttpResponseMessage response = await client.GetAsync("Projects/ProjectApprovedBudgets/" + projectID);// This URI shouldbe in the web.config file or passed via the AMP Service Layer.

                    if (response.IsSuccessStatusCode)
                    {
                        ProjectApprovedBudget projectApprovedBudget = Newtonsoft.Json.JsonConvert.DeserializeObject <ProjectApprovedBudget>(response.Content.ReadAsStringAsync().Result);

                        return(projectApprovedBudget);
                    }
                    else
                    {
                        Exception ex = new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase.ToString());
                        // Executes the error engine (ProjectID is optional, exception)
                        errorengine.LogError(projectID, ex, user);
                        throw ex;
                    }
                }
                catch (Exception ex)
                {
                    // Executes the error engine (ProjectID is optional, exception)
                    errorengine.LogError(projectID, ex, user);
                    throw ex;
                }
            }
        }
        protected async override Task <Email> ProcessEmail(string workflowTaskId, string projectId, string comments, string recipient, string user, string pageUrl)
        {
            Email email;

            if (workflowTaskId == Constants.CloseProjectTaskId.ToString())
            {
                email = new RejectCloseProjectEmail();
            }
            else if (workflowTaskId == Constants.ArchiveProject.ToString())
            {
                email = new RejectArchiveProjectEmail();
            }
            else
            {
                email = new RejectProjectWorkflowEmail();
            }

            await email.SetEmailPeople(_ampRepository, _personService, user, recipient, projectId);

            email.SetSROText();
            email.Subject = String.Format(email.Subject, projectId, _ampRepository.GetProject(projectId).Title);
            email.AMPlink = String.Format(email.AMPlink, AMPUtilities.BaseUrl(), projectId, workflowTaskId);
            email.Body    = String.Format(email.Body, email.Recipient.Forename, email.Sender.Forename, email.AMPlink, email.sroText);

            return(email);
        }
コード例 #4
0
        public void SendEmail(string aTo, string aCc, string aBcc, string aFrom, string aSubject, string aBody, MailPriority aPriority)
        {
            string from = aFrom, body = aBody.Replace('\r', ' ').Replace('\n', ' ');

            aSubject = aSubject.Replace('\r', ' ').Replace('\n', ' ');
            MailMessage mail = new MailMessage(from, aTo, aSubject, aBody);

            try
            {
                if (!String.IsNullOrEmpty(aCc))
                {
                    string[] CCId = aCc.Split(',');

                    foreach (string CCEmail in CCId)
                    {
                        mail.CC.Add(new MailAddress(CCEmail)); //Adding Multiple CC email Id
                    }
                }


                if (!String.IsNullOrEmpty(aBcc))
                {
                    mail.Bcc.Add(new MailAddress(aBcc));
                }


                if (mail.To.Count == 0 && mail.CC.Count == 0)
                {
                    body = string.Format("No recipients were specified for the below email. Investigation is required.<br /><br />{0}", body);
                    body = body + "</span>";
                    mail = new MailMessage(from, aTo, aSubject, body);
                }
                else
                {
                    mail.Bcc.Add(new MailAddress(aTo, from));
                }

                if (AMPUtilities.AppMode() == "DEV")
                {
                    body = string.Format("In LIVE environment the email would have been sent to {0} <br /><br />CC:{1}<br /><br />{2}", aTo, aCc, body);
                    mail = new MailMessage(from, AMPUtilities.TestEmail(), aSubject, body);
                }

                mail.Priority   = aPriority;
                mail.IsBodyHtml = true;

                //Copy AMPFeedback in for all email comms.
                mail.Bcc.Add(new MailAddress(ConfigurationManager.AppSettings["AMPFeedback"].ToString()));

                SmtpClient client = new SmtpClient(AMPUtilities.SMTPClient());
                client.UseDefaultCredentials = true;

                client.Send(mail);
            }
            catch (Exception ex)
            {
                string exc = ex.ToString();
            }
        }
コード例 #5
0
 private async Task SetSenderEmail(IPersonService personService, string sender)
 {
     try
     {
         Sender = await personService.GetPersonDetails(sender);
     }
     catch (Exception exception)
     {
         throw new HttpRequestException("Person Service threw an error when retrieving details for sender " + sender +
                                        " with a message: " + exception.Message);
     }
     From = AMPUtilities.SenderEmail();
 }
コード例 #6
0
        public async Task <IEnumerable <SupplierVM> > GetSearchSuppliers(IEnumerable <String> searchString, string user)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(AMPUtilities.FinanceWebServiceUrl());                                // We should store this in the web.config file
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // This probably removes the need to have the config in the API

                try
                {
                    // string logonName = empNo.Substring(5);
                    string queryString = BuildQueryStringFromList(searchString.ToList());


                    // HTTP GET

                    HttpResponseMessage response = await client.GetAsync("API/ProjectAPI/GetSearchSuppliers/?" + queryString);// This URI shouldbe in the web.config file or passed via the AMP Service Layer.



                    if (response.IsSuccessStatusCode)
                    {
                        IEnumerable <SupplierVM> suppliers = JsonConvert.DeserializeObject <IEnumerable <SupplierVM> >(response.Content.ReadAsStringAsync().Result);

                        return(suppliers);
                    }
                    else if (response.StatusCode == HttpStatusCode.NotFound)
                    {
                        //This user has no projects to get budgets for.
                        return(null);
                    }
                    else
                    {
                        Exception ex =
                            new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase.ToString());
                        // Executes the error engine (ProjectID is optional, exception)
                        errorengine.LogError(ex, user);
                        throw ex;
                    }
                }
                catch (Exception ex)
                {
                    // Executes the error engine (ProjectID is optional, exception)
                    errorengine.LogError(ex, user);
                    throw ex;
                }
            }
        }
        protected override async Task <Email> ProcessEmail(string workflowTaskId, string projectId, string comments,
                                                           string recipient, string user, string pageUrl)
        {
            Email email = new HoDAlertEmail();

            //Get the HoD alert List

            //Decide who gets the e-mail and who is on the cc list.
            await email.SetHoDAlertPeople(_ampRepository, _personService, user, projectId);

            //Get the project approved budget.

            email.SetSROText();
            email.AMPlink = email.AMPlink = String.Format(email.AMPlink, AMPUtilities.BaseUrl(), projectId, workflowTaskId);
            email.Subject = String.Format(email.Subject, projectId, _ampRepository.GetProject(projectId).Title);
            email.Body    = String.Format(email.Body, email.Recipient.Forename, email.Sender.Forename + ' ' + email.Sender.Surname, email.AMPlink, email.sroText);

            return(email);
        }
コード例 #8
0
        public bool PostRiskRegisterItem(RiskItemVM riskItemVm, string user)
        {
            riskItemVm.MitigationStrategy = AMPUtilities.CleanText(riskItemVm.MitigationStrategy);
            riskItemVm.Comments           = AMPUtilities.CleanText(riskItemVm.Comments);
            riskItemVm.RiskDescription    = AMPUtilities.CleanText(riskItemVm.RiskDescription);
            riskItemVm.ExternalOwner      = AMPUtilities.CleanText(riskItemVm.ExternalOwner);
            RiskRegisterBuilder builder = new RiskRegisterBuilder(riskItemVm, user);

            builder.BuildRiskRegisterItem();
            RiskRegister riskRegister = builder.RiskRegister;

            if (riskRegister.RiskID == 0)
            {
                _ampRepository.InsertRiskItem(riskRegister);
            }
            else
            {
                _ampRepository.UpdateRiskItem(riskRegister);
            }
            _ampRepository.Save();

            return(true);
        }
コード例 #9
0
 private void SetTaskDescription(Int32 taskId)
 {
     TaskDescription = AMPUtilities.GetEnumDescription((WorkflowType)(taskId));
 }
コード例 #10
0
        protected async override Task <Email> ProcessEmail(string workflowTaskId, string projectId, string comments, string recipient, string user, string pageUrl)
        {
            Email email;

            //switch (workflowTaskId)
            //{
            //    case Constants.WorkflowTaskId.ApproveProject:

            //    default:
            //}

            if (workflowTaskId == Constants.ArchiveProject.ToString())
            {
                email = new RequestArchiveEmail();
            }
            else if (workflowTaskId == Constants.ApproveProjectTask.ToString())
            {
                email = new RequestApprovalEmail();
            }
            else if (workflowTaskId == Constants.ReApproveProjectTaskId.ToString())
            {
                email = new RequestReApprovalEmail();
            }
            else if (workflowTaskId == Constants.PlannedEndDate.ToString())
            {
                email = new RequestPlannedEndDateEmail();
            }
            else if (workflowTaskId == Constants.ApproveAD.ToString())
            {
                email = new RequestAandDApprovalEmail();
            }
            else if (workflowTaskId == Constants.FastTrack.ToString())
            {
                email = new RequestFastTrackApprovalEmail();
            }
            else if (workflowTaskId == Constants.CloseProjectTaskId.ToString())
            {
                email = new RequestCloseProjectEmail();
            }
            else if (workflowTaskId == Constants.CancelWorkflow.ToString())
            {
                email = new RequestCancelEmail();
            }
            else if (workflowTaskId == Constants.ReOpenProject.ToString())
            {
                email = new RequestReOpenProjectEmail();
            }
            else
            {
                return(null);
            }

            await email.SetEmailPeople(_ampRepository, _personService, user, recipient, projectId);

            email.SetSROText();
            email.AMPlink = String.Format(email.AMPlink, AMPUtilities.BaseUrl(), projectId, workflowTaskId);
            email.Subject = String.Format(email.Subject, projectId, _ampRepository.GetProject(projectId).Title);
            email.Body    = String.Format(email.Body, email.Recipient.Forename, email.Sender.Forename, comments, email.AMPlink, email.sroText);

            return(email);
        }