Пример #1
0
        public Contact CreateContact(ContactRequestModel crmRequest)
        {
            Contact contacts = new Contact
            {
                FullName     = crmRequest.FullName,
                CompanyName  = crmRequest.CompanyName,
                Position     = crmRequest.Position,
                Country      = crmRequest.Country,
                Email        = crmRequest.Email,
                GuID         = Guid.NewGuid(),
                DateInserted = DateTime.Now,
                DateModified = DateTime.Now,
                EmailLists   = new List <EmailList>()
            };

            return(contacts);
        }
Пример #2
0
        public async Task <bool> UpdateContact(Guid guid, ContactRequestModel contact)
        {
            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                Contact dbContactToUpdate;
                try
                {
                    dbContactToUpdate = await db.Contacts.FirstOrDefaultAsync(c => c.GuID == guid);
                }
                catch
                {
                    throw;
                }
                if (dbContactToUpdate == null)
                {
                    return(false);
                }
                dbContactToUpdate.FullName    = contact.FullName;
                dbContactToUpdate.Country     = contact.Country;
                dbContactToUpdate.Position    = contact.Position;
                dbContactToUpdate.CompanyName = contact.CompanyName;
                dbContactToUpdate.Email       = contact.Email;

                db.Entry(dbContactToUpdate).State = EntityState.Modified;
                try
                {
                    await db.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await ContactExistsAsync(guid))
                    {
                        return(false);
                    }
                    else
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
                return(true);
            }
        }
        public JsonResult CreateEntry([FromBody] ContactRequestModel data)
        {
            string retval = "ok";

            DriveApiService service = new DriveApiService();


            service.UpdateQueriesSheet(data.Name,
                                       data.EmailAddress,
                                       data.PhoneNumber,
                                       data.Subject,
                                       data.Message,
                                       data.RequestSource);


            //"*****@*****.**"
            string OwnerContactEmailBodyString =
                GetOwnerContactEmailBodyString(data);

            string CustomerContactEmailBodyString =
                GetCustomerContactEmailBodyString(data);

            List <string> owneremails = new List <string>();

            owneremails.Add("*****@*****.**");

            List <string> receipientemails = new List <string>();

            receipientemails.Add(data.EmailAddress);

            service.SendEmail(OwnerContactEmailBodyString,
                              "Enquiry Received",
                              owneremails,
                              new List <AttachmentItem>());

            service.SendEmail(CustomerContactEmailBodyString,
                              "Enquiry Received",
                              receipientemails,
                              new List <AttachmentItem>());


            return(new JsonResult(new { result = retval }));;
        }
Пример #4
0
        public async Task <ContactResponseModel> AddContact(ContactRequestModel contact)
        {
            using (DbContextTransaction transaction = db.Database.BeginTransaction())
            {
                try
                {
                    var contacts = factory.CreateContact(contact);
                    db.Contacts.Add(contacts);
                    await db.SaveChangesAsync();

                    transaction.Commit();
                    var response = factory.CreateContactResponseModel(contacts);
                    return(response);
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
Пример #5
0
        public ActionResult Contact(ContactRequestModel model)
        {
            if (ModelState.IsValid)
            {
                CustomerContact contact = new CustomerContact()
                {
                    ContactName = model.Name,
                    Phone       = model.Phone,
                    Email       = model.Email,
                    MessageBody = model.Message
                };

                _customerContactRepository.Insert(contact);

                return(View("ContactConfirmation", model));
            }
            else
            {
                return(View("Contact", model));
            }
        }
        private string ApplyEmailTemplate(ContactRequestModel model, string filename)
        {
/*
 * <p>Enquiry Type: &lt;NONE-ENQ-TYPE&gt;</p>
 * <p>Name: &lt;NONE-NAME&gt;</p>
 * <p>Email: &lt;NONE-EMAIL-ADDRESS&gt;</p>
 * <p>Subject: &lt;NONE-SUBJECT&gt;</p>
 * <p>Message: &lt;NONE-MESSAGE&gt;</p>
 * <p>DateReceived: &lt;NONE-DATE-RECEIVED&gt;</p>
 */

            string retval = string.Empty;

            retval = System.IO.File.ReadAllText(filename);
            //retval = System.IO.File.ReadAllText(@"D:\home\site\wwwroot\" + filename);

            retval = retval.Replace("NONE-NAME", model.Name);
            retval = retval.Replace("NONE-ENQ-TYPE", model.RequestSource);
            retval = retval.Replace("NONE-EMAIL-ADDRESS", model.EmailAddress);
            retval = retval.Replace("NONE-SUBJECT", model.Subject);
            retval = retval.Replace("NONE-DATE-RECEIVED", DateTime.Now.ToShortDateString());
            retval = retval.Replace("NONE-MESSAGE", model.Message);
            return(retval);
        }
        public HttpResponseMessage GetContact(ContactRequestModel contactRequestModel)
        {
            HttpResponseMessage response;

            try
            {
                if (contactRequestModel == null || !IsValidEmail(contactRequestModel.Email))
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, InvalidInputParametersMessage);

                    return(response);
                }

                bool isContactIdentified = _xConnectService.IdentifyContact(contactRequestModel.Email);
                if (!isContactIdentified)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, InvalidContactIdentifiedMessage);

                    return(response);
                }

                ContactModel contactModel = _xConnectService.GetContact(contactRequestModel.Email);

                response = Request.CreateResponse(HttpStatusCode.OK, contactModel);

                return(response);
            }
            catch (Exception ex)
            {
                Log.Error($"Error in XConnectApiController.GetContact(): while getting contact details with email: {contactRequestModel?.Email}", ex, this);

                response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, InternalServerErrorMessage);

                return(response);
            }
        }
        private string GetOwnerContactEmailBodyString(ContactRequestModel model)
        {
            string result = ApplyEmailTemplate(model, "OwnerCustomerRequestTemplate.htm");

            return(result);
        }
Пример #9
0
        public async Task <string> ResetForDemo()
        {
            var group1 = new List <ContactResponseModel>();
            var group2 = new List <ContactResponseModel>();
            var group3 = new List <ContactResponseModel>();

            try
            {
                await db.Database.ExecuteSqlCommandAsync("delete from Contacts");

                await db.Database.ExecuteSqlCommandAsync("delete from MailingLists");

                await db.SaveChangesAsync();

                var test1 = new ContactRequestModel {
                    FullName = "Aram Zhamkochyan", CompanyName = "BetConstruct", Position = "Intern", Country = "Armenia", Email = "*****@*****.**"
                };
                var test2 = new ContactRequestModel {
                    FullName = "Lusine Khachatryan", CompanyName = "BetConstruct", Position = "Intern", Country = "Armenia", Email = "*****@*****.**"
                };
                var test3 = new ContactRequestModel {
                    FullName = "Sargis Chilingaryan", CompanyName = "BetConstruct", Position = "Front-end developer", Country = "Armenia", Email = "*****@*****.**"
                };
                var test4 = new ContactRequestModel {
                    FullName = "Davit Hunanyan", CompanyName = "STDev", Position = "Frontend developer", Country = "Armenia", Email = "*****@*****.**"
                };
                var test5 = new ContactRequestModel {
                    FullName = "Vahan Kalenteryan", CompanyName = "BetConstruct", Position = "Front-end developer", Country = "Armenia", Email = "*****@*****.**"
                };
                var test6 = new ContactRequestModel {
                    FullName = "Gayane Khachatryan", CompanyName = "BetConstruct", Position = "Back-end developer", Country = "Armenia", Email = "*****@*****.**"
                };
                var test7 = new ContactRequestModel {
                    FullName = "Narek Yegoryan", CompanyName = "BetContstruct", Position = "Back-end developer", Country = "Armenia", Email = "*****@*****.**"
                };
                var test8 = new ContactRequestModel {
                    FullName = "Aghasi Lorsabyan", CompanyName = "TUMO", Position = "Trainer", Country = "Kharabakh", Email = "*****@*****.**"
                };
                var test9 = new ContactRequestModel {
                    FullName = "Khachatur Sukiasyan", CompanyName = "SIL Group", Position = "Owner", Country = "Armenia", Email = "*****@*****.**"
                };
                var test10 = new ContactRequestModel {
                    FullName = "Meri Sahakyan", CompanyName = "BetConstruct", Position = "Intern", Country = "Armenia", Email = "*****@*****.**"
                };
                var test11 = new ContactRequestModel {
                    FullName = "Van Hakobyan", CompanyName = "BetConstruct", Position = "Intern", Country = "Armenia", Email = "*****@*****.**"
                };
                var test12 = new ContactRequestModel {
                    FullName = "Hovhanes Nalbandyan", CompanyName = "BetConstruct", Position = "Developer", Country = "Armenia", Email = "*****@*****.**"
                };
                var test13 = new ContactRequestModel {
                    FullName = "Lusine Hovsepyan", CompanyName = "MIC Armenia", Position = "Developer", Country = "Armenia", Email = "*****@*****.**"
                };
                var test14 = new ContactRequestModel {
                    FullName = "Tsovinar Ghazaryan", CompanyName = "MIC Armenia", Position = "Back-end developer", Country = "Armenia", Email = "*****@*****.**"
                };
                foreach (var testContact in new[] { test1, test2, test4, test5, test6 })
                {
                    group1.Add(await AddContact(testContact));
                }
                foreach (var testContact in new[] { test3, test7, test10, test11, test12, test13 })
                {
                    group2.Add(await AddContact(testContact));
                }
                foreach (var testContact in new[] { test8, test9, test14 })
                {
                    group3.Add(await AddContact(testContact));
                }

                var testMailingList1 = await AddMailingList("OurGroup");

                var testMailingList2 = await AddMailingList("MIC Armenia");

                var testMailingList3 = await AddMailingList("VIP");

                var ml1 = await AddContactsToMailingLists(testMailingList1.MailingListId, group1.Select(x => x.Guid.ToString()).ToArray());

                var ml2 = await AddContactsToMailingLists(testMailingList2.MailingListId, group2.Select(x => x.Guid.ToString()).ToArray());

                var ml3 = await AddContactsToMailingLists(testMailingList3.MailingListId, group3.Select(x => x.Guid.ToString()).ToArray());

                if (ml1 == null || ml2 == null || ml3 == null)
                {
                    return(null);
                }
                await db.SaveChangesAsync();

                var path = HttpContext.Current?.Request.MapPath("~//Templates//Demo page.html");
                return(File.ReadAllText(path));
            }
            catch
            {
                return(null);
            }
        }
 public void Post(ContactRequestModel contactRequestModel)
 {
     var contactRequestMsgEntity = contactApiMapper.MapContactRequestMsgEntity(contactRequestModel);
     var result = contactService.CreateContact(contactRequestMsgEntity);
 }
Пример #11
0
        private List <ContactRequestModel> ReadExcelFile(string path)
        {
            var strProperties        = new string[5];
            var contactRequestModels = new List <ContactRequestModel>();
            ContactRequestModel model;
            var j = 0;

            using (var myDoc = SpreadsheetDocument.Open(path, false))
            {
                var    workbookPart   = myDoc.WorkbookPart;
                var    sheets         = myDoc.WorkbookPart.Workbook.GetFirstChild <Sheets>().Elements <Sheet>();
                var    relationshipId = sheets?.First().Id.Value;
                var    worksheetPart  = (WorksheetPart)myDoc.WorkbookPart.GetPartById(relationshipId);
                var    sheetData      = worksheetPart.Worksheet.GetFirstChild <SheetData>();
                var    i = 1;
                string value;
                var    emailValidator = new EmailAddressAttribute();
                foreach (var r in sheetData.Elements <Row>())
                {
                    foreach (var c in r.Elements <Cell>())
                    {
                        if (c == null)
                        {
                            continue;
                        }

                        value = c.InnerText;
                        if (c.DataType != null)
                        {
                            var stringTable = workbookPart.GetPartsOfType <SharedStringTablePart>().FirstOrDefault();
                            if (stringTable != null)
                            {
                                value = stringTable.SharedStringTable.
                                        ElementAt(int.Parse(value)).InnerText;
                            }
                        }
                        strProperties[j] = value;
                        j = j + 1;
                    }
                    if (i == 1 &&
                        (strProperties[0] != "FullName" || strProperties[1] != "CompanyName" ||
                         strProperties[2] != "Position" || strProperties[3] != "Country" || strProperties[4] != "Email"))
                    {
                        return(null);
                    }
                    j = 0;
                    i = i + 1;
                    if (i == 2)
                    {
                        continue;
                    }
                    model = new ContactRequestModel {
                        FullName = strProperties[0], CompanyName = strProperties[1], Position = strProperties[2], Country = strProperties[3], Email = strProperties[4]
                    };
                    if (strProperties.Any(string.IsNullOrEmpty) || !emailValidator.IsValid(strProperties[4]))
                    {
                        contactRequestModels.Add(null);
                    }
                    else
                    {
                        contactRequestModels.Add(model);
                    }
                }
                return(contactRequestModels);
            }
        }
Пример #12
0
        public IActionResult Contact()
        {
            var model = new ContactRequestModel();

            return(View(model));
        }