Пример #1
0
 public ActionResult ClaimForm(long id)
 {
     using (var db = new InnosixEntities())
     {
         var claimFormViewModel = new ClaimFormViewModel
         {
             TcBasicInfo        = db.TCBasicInfo.Find(id),
             AspNetUsersTcClaim = new AspNetUsersTcClaim {
                 TCid = id
             }
         };
         return(View(claimFormViewModel));
     }
 }
Пример #2
0
        public ActionResult UnknownClaimForm(ClaimFormViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var claimantDTO = Mapper.Map <ClaimFormViewModel, ClaimantDTO>(model);

                    claimantDTO.SubmitSource    = "Web";
                    claimantDTO.SubmitDate      = DateTime.Now;
                    claimantDTO.IPAddress       = GetIPAddress();
                    claimantDTO.UserAgentString = GetUserAgentString();
                    claimantDTO.SessionID       = Session.SessionID;

                    string caseCode = ConfigurationManager.AppSettings["CaseCode"];
                    var    claimId  = claimService.SaveUnknownClaim(claimantDTO);

                    string caseName    = ConfigurationManager.AppSettings["CaseName"];
                    string fullClaimId = caseCode + "-" + claimId;

                    if (!string.IsNullOrEmpty(model.Email))
                    {
                        try
                        {
                            SmtpClient smtp = new SmtpClient();
                            smtp.Send(GetConfirmationMail(model.Email, caseName, claimantDTO.SubmitDate, fullClaimId));
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError("", "Unable to send confirmation email.");
                            return(RedirectToAction("Index", "Error"));
                        }
                    }

                    return(RedirectToAction("ClaimSubmitted", new { fullClaimId = fullClaimId }));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your administrator.");
                    return(RedirectToAction("Index", "Error"));
                }
            }

            return(View(model));
        }
Пример #3
0
        public ActionResult UnknownClaimForm()
        {
            ClaimFormViewModel model = new ClaimFormViewModel();

            return(View(model));
        }
Пример #4
0
        public async Task <ActionResult> ClaimForm(ClaimFormViewModel claimForm)
        {
            var userId    = User.Identity.GetUserId();
            var userEmail = User.Identity.GetUserName();

            using (var db = new InnosixEntities())
            {
                var claim = claimForm.AspNetUsersTcClaim;
                claim.AspNetUserId = userId;

                var isActive = db.TCActive.First(x => x.TCid == claim.TCid).IsActive;

                var automaticClaims = Environment.GetEnvironmentVariable("SendGridAutomaticClaims");
                if (!isActive && automaticClaims == "true")
                {
                    var claimed = AutomaticClaimAccept(claim.AspNetUserId, claim.TCid);
                    if (claimed)
                    {
                        return(RedirectToAction("Index"));
                    }

                    ViewBag.Message = "Error accured when claiming tech company";
                    return(View("ClaimForm", claimForm));
                }

                var isInClaims = db.AspNetUsersTcClaim.Any(x => x.AspNetUserId == userId && x.TCid == claim.TCid);
                if (isInClaims)
                {
                    ViewBag.Message = "Claim already sent for this company";
                    return(View("ClaimForm", claimForm));
                }

                db.AspNetUsersTcClaim.Add(claim);
                db.SaveChanges();

                if (isActive)
                {
                    var tc = db.TCBasicInfo.Find(claim.TCid);

                    var plainTextContent = $@"Claim request.

User email: {userEmail}
User phone number: {claim.PhoneNumber}
Company name: {tc.CompanyName}
Company email: {tc.CompanyEmail}
Company website: {tc.CompanyWebsite}

Claim description: {claim.Description}";

                    var htmlContent = $@"Claim request.<br/>
<br/>
User email: {userEmail}<br/>
User phone number: {claim.PhoneNumber}<br/>
Company name: {tc.CompanyName}<br/>
Company email: {tc.CompanyEmail}<br/>
Company website: {tc.CompanyWebsite}<br/>
<br/>
Claim description: {claim.Description}";

                    var tcOwnerId    = db.AspNetUsersToTC.First(x => x.TCid == claim.TCid).AspNetUserId;
                    var tcOwnerEmail = db.AspNetUsers.First(x => x.Id == tcOwnerId).Email;
                    var adminEmail   = Environment.GetEnvironmentVariable("SendGridAdminEmail");

                    IEnumerable <string> emails = new List <string> {
                        userEmail, tcOwnerEmail, adminEmail
                    };
                    await _emailHelper.SendSingleEmailToMultipleRecipients(emails, $"Claim request for company: {tc.CompanyName}", plainTextContent, htmlContent);
                }
            }

            ViewBag.Message = "Claim sent";
            return(View());
        }