Exemplo n.º 1
0
        public JsonResponse <int> CorporateEnquiry(CorporateTieUpEnquiry enquiry)
        {
            JsonResponse <int> response = new JsonResponse <int>();

            if (!ModelState.IsValid)
            {
                response.FailedValidations = ModelState.Keys.ToArray();
                response.Message           = string.Format("Kindly check {0}. It is missing or in incorrect format.", response.FailedValidations[0].Split('.').LastOrDefault());
                return(response);
            }
            try
            {
                enquiry.CreatedDate = DateTime.Now;
                enquiry.Status      = (int)AspectEnums.EnquiryStatus.Received;
                _context.CorporateTieUpEnquiries.Add(enquiry);
                response.IsSuccess = _context.SaveChanges() > 0 ? true : false;

                if (response.IsSuccess)
                {
                    response.StatusCode   = "200";
                    response.Message      = "Your enquiry is successfully posted.  We will send you email shortly.";
                    response.SingleResult = enquiry.ID;
                    log.Info("[Success] CorporateEnquiry for Email: " + enquiry.Email);
                }
            }
            catch (Exception ex)
            {
                response.IsSuccess  = false;
                response.StatusCode = "500";
                response.Message    = ex.Message;
            }

            return(response);
        }
Exemplo n.º 2
0
        public JsonResponse <int> SendCorporateTieUpEmail(CorporateTieUpEnquiry model)
        {
            JsonResponse <int> response = new JsonResponse <int>();

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <CorporateTieUpEnquiry, EmailModel>();
            });

            IMapper    iMapper = config.CreateMapper();
            EmailModel email   = iMapper.Map <CorporateTieUpEnquiry, EmailModel>(model);

            EmailHelper eHelper      = new EmailHelper();
            string      otherContent = "Company: " + model.CompanyName;

            email.Subject = "Enquiry for Corporate Tie Up.";
            int status = eHelper.PrepareAndSendEmail(email, otherContent);

            if (status == (int)AspectEnums.EmailStatus.Sent)
            {
                log.Info(string.Format("Email successfully sent to {0} at {1}.", model.Name, model.Email));
                response.Message      = string.Format("Email successfully sent to {0} at {1}.", model.Name, model.Email);
                response.StatusCode   = "200";
                response.IsSuccess    = true;
                response.SingleResult = status;
            }
            else
            {
                log.Info(string.Format("Could not send email to {0} at {1}.", model.Name, model.Email));
                response.Message      = string.Format("Could not send email to {0} at {1}.", model.Name, model.Email);
                response.StatusCode   = "500";
                response.IsSuccess    = false;
                response.SingleResult = status;
            }

            return(response);
        }