예제 #1
0
        public PartialViewResult UpdateCustomerContact(Int32 id)
        {
            SR_Log_DatabaseSQLEntities db          = new SR_Log_DatabaseSQLEntities();
            tblCustContact             custcontact = db.tblCustContacts.Where(x => x.Id == id).FirstOrDefault();
            CustomerContactViewModel   contact     = new CustomerContactViewModel();

            contact.CustomerContact = custcontact.CustomerContact;
            contact.ContactEmail    = custcontact.ContactEmail;
            contact.ContactPhone    = custcontact.ContactPhone;
            contact.Id         = custcontact.Id;
            contact.CustomerId = custcontact.CustomerId;

            if (custcontact.IsPrimaryContact == true)
            {
                contact.IsPrimaryContact = true;
            }
            else
            {
                contact.IsPrimaryContact = false;
            }
            ViewBag.Adddisable        = false;
            ViewBag.CustomerId        = custcontact.CustomerId;
            ViewBag.CustomerContactId = custcontact.Id;
            return(PartialView("CreateCustomerContact", contact));
        }
예제 #2
0
        /// <summary>
        /// Add cusomter contact to temp data
        /// </summary>
        /// <param name="name"></param>
        /// <param name="contactNumber"></param>
        /// <returns></returns>
        public ActionResult AddCustomerContact(CustomerContactViewModel customerContactViewModel)
        {
            //List<CustomerContactViewModel> customerContactViewModelList=new List<CustomerContactViewModel>();
            //return PartialView("_CustomerContacts", customerContactViewModelList);
            List <CustomerContactViewModel> customerContactViewModelList;
            int maxId = 0;

            if (TempData[_tempCustomerContactKey] != null && TempData[_tempCustomerContactKey].ToString() != "")
            {
                string jsonStr = TempData[_tempCustomerContactKey].ToString();
                customerContactViewModelList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <CustomerContactViewModel> >(jsonStr);// (List<CustomerContactViewModel>)TempData[_tempCustomerContactKey];
                maxId = customerContactViewModelList.Max(x => x.TempId);
            }
            else
            {
                customerContactViewModelList = new List <CustomerContactViewModel>();
            }
            if (!string.IsNullOrEmpty(customerContactViewModel.ContactNumber) && !string.IsNullOrEmpty(customerContactViewModel.Name))
            {
                customerContactViewModelList.Add(new CustomerContactViewModel()
                {
                    ContactNumber = customerContactViewModel.ContactNumber, Name = customerContactViewModel.Name, TempId = ++maxId
                });
            }

            TempData[_tempCustomerContactKey] = Newtonsoft.Json.JsonConvert.SerializeObject(customerContactViewModelList);
            return(PartialView("_CustomerContacts", customerContactViewModelList));
        }
예제 #3
0
        public PartialViewResult CreateCustomerContact(int customerid)
        {
            CustomerContactViewModel custcontact = new CustomerContactViewModel();

            custcontact.CustomerId    = customerid;
            ViewBag.CustomerId        = customerid;
            ViewBag.CustomerContactId = 0;
            return(PartialView(custcontact));
        }
예제 #4
0
        public ActionResult CreateCustomerContact(CustomerContactViewModel custconact)
        {
            SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities();

            if (custconact.CustomerId != 0)
            {
                var existcustcontact = db.tblCustContacts.Where(x => x.CustomerContact.Trim().ToUpper() == custconact.CustomerContact.Trim().ToUpper() && x.CustomerId == custconact.CustomerId).FirstOrDefault();
                if (existcustcontact != null)
                {
                    ViewBag.Message = "This Contact already present. Please add different name And Try Again.";
                    return(Json(custconact, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    CustomerRepository objdata = new CustomerRepository();
                    if (string.IsNullOrEmpty(custconact.ContactEmail) == false)
                    {
                        custconact.ContactEmail = custconact.ContactEmail.ToUpper();
                    }

                    if (string.IsNullOrEmpty(custconact.ContactPhone) == false)
                    {
                        custconact.ContactPhone = custconact.ContactPhone.ToUpper();
                    }

                    if (string.IsNullOrEmpty(custconact.CustomerContact) == false)
                    {
                        custconact.CustomerContact = custconact.CustomerContact.ToUpper();
                    }


                    objdata.AddUpdateCustomerContact(custconact, "Add");
                }
            }

            //CustomerRepository _repository = new CustomerRepository();
            //var cust = _repository.GetCustomerDetails(custconact.CustomerId);
            tblCustContact cust = new tblCustContact();

            return(Json(cust, JsonRequestBehavior.AllowGet));



            //db.Products.InsertOnSubmit(product);
            //db.SubmitChanges();
            //return Json(cust, JsonRequestBehavior.AllowGet);

            //CustomerRepository _repository = new CustomerRepository();
            //var cust = _repository.GetCustomerDetails(2);
            //// parts.Add(new Part() {PartName="crank arm", PartId=1234});
            //cust.lstCustContact.Add(new tblCustContact() { Id = 0, CustomerId = 0, CustomerContact = product.CustomerContact, ContactEmail = product.ContactEmail, IsPrimaryContact = product.IsPrimaryContact });
            //return View("Index", cust);
        }
예제 #5
0
        public ActionResult List(int?customerId = null)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("List").ToInputLogString());

            try
            {
                CustomerInfoViewModel custInfoVM = new CustomerInfoViewModel();

                if (TempData["CustomerInfo"] != null)
                {
                    custInfoVM = (CustomerInfoViewModel)TempData["CustomerInfo"];
                    TempData["CustomerInfo"] = custInfoVM; // keep for change Tab
                }
                else
                {
                    return(RedirectToAction("Search", "Customer"));
                }

                Logger.Info(_logMsg.Clear().SetPrefixMsg("List").Add("CustomerId", custInfoVM.CustomerId).ToInputLogString());

                _commonFacade   = new CommonFacade();
                _customerFacade = new CustomerFacade();
                CustomerContactViewModel contactVM = new CustomerContactViewModel();
                contactVM.CustomerInfo = custInfoVM;

                if (custInfoVM.CustomerId.HasValue)
                {
                    // Contact list
                    contactVM.SearchFilter = new ContactSearchFilter
                    {
                        CustomerId = custInfoVM.CustomerId.Value,
                        PageNo     = 1,
                        PageSize   = _commonFacade.GetPageSizeStart(),
                        SortField  = "CardNo",
                        SortOrder  = "ASC"
                    };

                    contactVM.ContactList = _customerFacade.GetContactList(contactVM.SearchFilter);
                    ViewBag.PageSize      = contactVM.SearchFilter.PageSize;
                    ViewBag.PageSizeList  = _commonFacade.GetPageSizeList();
                    ViewBag.Message       = string.Empty;
                }

                return(View(contactVM));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("List").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
예제 #6
0
        public async Task <ActionResult> Contacts(int id)
        {
            Customer customer = await customerService.FindCustomersByIDAsync(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }

            var model = new CustomerContactViewModel(customer);

            return(View(model));
        }
예제 #7
0
        // GET: Customer/Details/5
        public ActionResult Details(int id)
        {
            CustomerViewModel customerVM = new CustomerViewModel();

            restProperties.Method     = "GetCustomerwithContacts";
            restProperties.MethodType = Method.GET;

            restProperties.Parameters = new List <CIRestParameter>();
            restProperties.Parameters.Add(new CIRestParameter()
            {
                key   = "id",
                value = id
            });

            IRestResponse <Customer> response = CIRestService.ExecuteRestRequest <Customer>(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                Customer customer = Newtonsoft.Json.JsonConvert.DeserializeObject <Customer>(response.Content);
                if (customer != null)
                {
                    customerVM.CustomerId       = customer.Id;
                    customerVM.FirstName        = customer.FirstName;
                    customerVM.LastName         = customer.LastName;
                    customerVM.CustomerContacts = new List <CustomerContactViewModel>();
                    foreach (CustomerContact contact in customer.CustomerContacts)
                    {
                        CustomerContactViewModel contactVM = new CustomerContactViewModel();
                        contactVM.CutsomerContactId = contact.Id;
                        contactVM.CustomerId        = contact.CustomerId;
                        contactVM.ContactTypeId     = contact.ContactTypeId;
                        contactVM.ContactTypeText   = contact.ContactType?.Type;
                        contactVM.ContactValue      = contact.ContactValue;
                        contactVM.ContactStatus     = contact.ContactStatus;
                        customerVM.CustomerContacts.Add(contactVM);
                    }
                }
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }

            return(View(customerVM));
        }
        //// GET: CustomerContact
        //public ActionResult Index()
        //{
        //    return View();
        //}

        //// GET: CustomerContact/Details/5
        //public ActionResult Details(int id)
        //{
        //    return View();
        //}

        // GET: CustomerContact/Create
        public ActionResult Create(int customerId)
        {
            CustomerContactViewModel    contactVm = new CustomerContactViewModel();
            List <ContactType>          contactTypes;
            Dictionary <string, string> ContactStatusList;

            GetContactTypesandStatus(out contactTypes, out ContactStatusList);

            contactVm.ContactStatusList = new SelectList(ContactStatusList, "Key", "Value");
            contactVm.ContactTypeList   = new SelectList(contactTypes, "Id", "Type");

            CustomerController customerController = new CustomerController();
            Customer           customer           = customerController.GetCustomer(customerId);

            contactVm.CustomerName = customer.FirstName + " " + customer.LastName;

            return(View(contactVm));
        }
        private CustomerContactViewModel GetCustomerContctInfo(int id)
        {
            CustomerContactViewModel    customerContactVm = new CustomerContactViewModel();
            List <ContactType>          contactTypes;
            Dictionary <string, string> ContactStatusList;

            GetContactTypesandStatus(out contactTypes, out ContactStatusList);

            customerContactVm         = new CustomerContactViewModel();
            restProperties.Controller = typeof(CustomerContact).Name;
            restProperties.Method     = "GetContactInformation";
            restProperties.MethodType = Method.GET;

            restProperties.Parameters = new List <CIRestParameter>();
            restProperties.Parameters.Add(new CIRestParameter()
            {
                key   = "id",
                value = id
            });

            IRestResponse <CustomerContact> response = CIRestService.ExecuteRestRequest <CustomerContact>(restProperties, client);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                CustomerContact customerContact = Newtonsoft.Json.JsonConvert.DeserializeObject <CustomerContact>(response.Content);
                if (customerContact != null)
                {
                    customerContactVm.CutsomerContactId = customerContact.Id;
                    customerContactVm.CustomerId        = customerContact.CustomerId;
                    customerContactVm.CustomerName      = customerContact.Customer?.FirstName + " " + customerContact.Customer?.LastName;
                    customerContactVm.ContactTypeList   = new SelectList(contactTypes, "Id", "Type", customerContact.ContactTypeId);
                    customerContactVm.ContactTypeId     = customerContact.ContactTypeId;
                    customerContactVm.ContactTypeText   = customerContact.ContactType?.Type;
                    customerContactVm.ContactValue      = customerContact.ContactValue;
                    customerContactVm.ContactStatus     = customerContact.ContactStatus;
                    customerContactVm.ContactStatusList = new SelectList(ContactStatusList, "Key", "Value", customerContact.ContactStatus);
                }
            }
            else
            {
                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
            }
            return(customerContactVm);
        }
        public ActionResult Edit(int id, CustomerContactViewModel contactVM)
        {
            try
            {
                CustomerContact contact = new CustomerContact();
                contact.Id            = contactVM.CutsomerContactId;
                contact.ContactTypeId = contactVM.ContactTypeId;
                contact.CustomerId    = contactVM.CustomerId;
                contact.ContactValue  = contactVM.ContactValue;
                contact.ContactStatus = contactVM.ContactStatus;
                // TODO: Add update logic here

                CIRestProperties restProperties = new CIRestProperties();
                restProperties.Controller = typeof(CustomerContact).Name;
                restProperties.Method     = "SaveContact";
                restProperties.MethodType = Method.POST;
                //restProperties.Body = customer;
                restProperties.Parameters = new List <CIRestParameter>();
                restProperties.Parameters.Add(new CIRestParameter()
                {
                    key   = "contact",
                    value = contact
                });

                IRestResponse <CustomerContact> response = CIRestService.ExecuteRestRequest <CustomerContact>(restProperties, client);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    contact = JsonConvert.DeserializeObject <CustomerContact>(response.Content);
                }
                else
                {
                    throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
                }

                return(RedirectToAction("Details", "Customer", new { id = contact.CustomerId }));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <int> SaveCustomerContactAsync(CustomerContactViewModel customerContactModel)
        {
            var objCustomerContact = new CustomerContactDetails
            {
                CustomerName  = customerContactModel.CustomerName,
                CellEmail     = customerContactModel.CellEmail,
                CompanyId     = customerContactModel.CompanyId,
                CellPhone     = customerContactModel.CellPhone,
                City          = customerContactModel.City,
                Email         = customerContactModel.Email,
                Name          = customerContactModel.Name,
                Phone         = customerContactModel.Phone,
                State         = customerContactModel.State,
                StreetAddress = customerContactModel.StreetAddress,
                Zip           = customerContactModel.Zip
            };
            var customerContact = await _customerContactRepository.CreateAsync(objCustomerContact);

            return(customerContact.CustomerContactId);
        }
예제 #12
0
 public ActionResult GetCustomerContact(int customerId, bool isIncludeItself = false)
 {
     if (customerId > 0)
     {//View Only
         ViewBag.IsViewOnly = true;
         List <CustomerContactViewModel> customerContactViewModelList = new List <CustomerContactViewModel>();
         if (!isIncludeItself)
         {
             customerContactViewModelList = _customerService.GetCustomerContactsByCustomer(customerId);
         }
         else
         {
             var customerModel = _customerService.CreateViewModel(customerId);
             customerContactViewModelList.Add(new CustomerContactViewModel()
             {
                 Id = customerModel.Id, CustomerId = customerModel.Id, Name = customerModel.LeaderName, ContactNumber = customerModel.ContactNumber
             });
             if (customerModel.CustomerContactViewModelList != null && customerModel.CustomerContactViewModelList.Count() > 0)
             {
                 customerContactViewModelList.AddRange(customerModel.CustomerContactViewModelList);
             }
         }
         return(PartialView("_CustomerContacts", customerContactViewModelList));
     }
     else
     {
         //Add and delete
         CustomerContactViewModel customerContactViewModel = new CustomerContactViewModel();
         if (TempData[_tempCustomerContactKey] != null && TempData[_tempCustomerContactKey].ToString() != "")
         {
             string jsonStr = TempData[_tempCustomerContactKey].ToString();
             var    customerContactViewModelList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <CustomerContactViewModel> >(jsonStr);// (List<CustomerContactViewModel>)TempData[_tempCustomerContactKey];
             ViewBag.CustomerContacts = customerContactViewModelList;
             TempData.Keep(_tempCustomerContactKey);
         }
         return(PartialView("_CustomerContactForm", customerContactViewModel));
     }
 }
        public ActionResult Delete(int id, CustomerContactViewModel contactVM)
        {
            try
            {
                CIRestProperties restProperties = new CIRestProperties();
                restProperties.Controller = typeof(CustomerContact).Name;
                restProperties.Method     = "RemoveContact";
                restProperties.MethodType = Method.GET;
                restProperties.Parameters = new List <CIRestParameter>();
                restProperties.Parameters.Add(new CIRestParameter()
                {
                    key   = "id",
                    value = id
                });

                IRestResponse <bool> response = CIRestService.ExecuteRestRequest <bool>(restProperties, client);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    if (response.Data)
                    {
                        return(RedirectToAction("Details", "Customer", new { id = contactVM.CustomerId }));
                    }
                    else
                    {
                        RedirectToAction("Delete", new { id = id });
                    }
                }

                throw new Exception("Error Message " + response.ErrorMessage + "\n  Exception:" + response.ErrorException);
                // TODO: Add delete logic here
            }
            catch
            {
                return(View());
            }
        }
예제 #14
0
        public ActionResult UpdateCustomerContact(CustomerContactViewModel custconact)
        {
            SR_Log_DatabaseSQLEntities db = new SR_Log_DatabaseSQLEntities();

            if (custconact.CustomerId != 0)
            {
                CustomerRepository objdata = new CustomerRepository();
                if (string.IsNullOrEmpty(custconact.ContactEmail) == false)
                {
                    custconact.ContactEmail = custconact.ContactEmail.ToUpper();
                }

                if (string.IsNullOrEmpty(custconact.ContactPhone) == false)
                {
                    custconact.ContactPhone = custconact.ContactPhone.ToUpper();
                }

                if (string.IsNullOrEmpty(custconact.CustomerContact) == false)
                {
                    custconact.CustomerContact = custconact.CustomerContact.ToUpper();
                }

                objdata.AddUpdateCustomerContact(custconact, "Update");

                tblCustomer customer = db.tblCustomers.Where(x => x.CustomerId == custconact.CustomerId).FirstOrDefault();
                var         act      = new ActivityRepository();
                act.AddActivityLog(Convert.ToString(Session["User"]), "Edit Contact", "UpdateCustomerContact", "Contacts for customer " + customer.CustomerName.ToUpper() + " edited by " + Convert.ToString(Session["User"]) + ".");
                //Call SaveActivityLog("frmAddCustomer", "Edit Contact", "Contacts for customer " & UCase(txtCustomerName.Text) & " edited by " & UserInfo.UserName)
            }


            //CustomerRepository _repository = new CustomerRepository();
            //var cust = _repository.GetCustomerDetails(custconact.CustomerId);
            tblCustContact cust = new tblCustContact();

            return(Json(cust, JsonRequestBehavior.AllowGet));
        }
예제 #15
0
        public ActionResult CustomerContactList(ContactSearchFilter searchFilter)
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Search CustomerContactList").Add("CustomerId", searchFilter.CustomerId).ToInputLogString());

            try
            {
                if (ModelState.IsValid)
                {
                    _commonFacade   = new CommonFacade();
                    _customerFacade = new CustomerFacade();
                    CustomerContactViewModel contactVM = new CustomerContactViewModel();
                    contactVM.SearchFilter = searchFilter;

                    contactVM.ContactList = _customerFacade.GetContactList(contactVM.SearchFilter);
                    ViewBag.PageSize      = contactVM.SearchFilter.PageSize;
                    ViewBag.PageSizeList  = _commonFacade.GetPageSizeList();

                    Logger.Info(_logMsg.Clear().SetPrefixMsg("CustomerContactList").ToSuccessLogString());
                    return(PartialView("~/Views/Contact/_CustomerContactList.cshtml", contactVM));
                }

                return(Json(new
                {
                    Valid = false,
                    Error = string.Empty,
                    Errors = GetModelValidationErrors()
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Search CustomerContactList").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
        // GET: CustomerContact/Delete/5
        public ActionResult Delete(int id)
        {
            CustomerContactViewModel customerContactVm = GetCustomerContctInfo(id);

            return(View(customerContactVm));
        }
예제 #17
0
        public void AddUpdateCustomerContact(CustomerContactViewModel model, string Flag)
        {
            using (var context = new SR_Log_DatabaseSQLEntities())
            {
                if (Flag == "Add")
                {
                    if (model.IsPrimaryContact == true)
                    {
                        var ExistCust = (from c in context.tblCustContacts
                                         where c.CustomerId == model.CustomerId
                                         select c).ToList();
                        if (ExistCust.Count > 0)
                        {
                            foreach (var cust in ExistCust)
                            {
                                if (cust.IsPrimaryContact == true)
                                {
                                    tblCustContact result = (from c in context.tblCustContacts
                                                             where c.Id == cust.Id
                                                             select c).SingleOrDefault();
                                    if (result != null)
                                    {
                                        result.IsPrimaryContact = false;
                                        context.SaveChanges();
                                    }
                                }
                            }
                        }
                    }

                    var customer = context.USP_TT_InsertCustContacts(Convert.ToInt32(model.CustomerId), model.CustomerContact, model.ContactPhone, model.ContactEmail, model.IsPrimaryContact);
                }
                else
                {
                    if (model.IsPrimaryContact == true)
                    {
                        var ExistCust = (from c in context.tblCustContacts
                                         where c.CustomerId == model.CustomerId
                                         select c).ToList();
                        if (ExistCust.Count > 0)
                        {
                            foreach (var cust in ExistCust)
                            {
                                if (cust.IsPrimaryContact == true)
                                {
                                    tblCustContact r = (from c in context.tblCustContacts
                                                        where c.Id == cust.Id && c.Id != model.Id
                                                        select c).SingleOrDefault();
                                    if (r != null)
                                    {
                                        r.IsPrimaryContact = false;
                                        context.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                    tblCustContact result = (from c in context.tblCustContacts
                                             where c.Id == model.Id
                                             select c).SingleOrDefault();

                    result.CustomerContact  = model.CustomerContact;
                    result.ContactPhone     = model.ContactPhone;
                    result.ContactEmail     = model.ContactEmail;
                    result.IsPrimaryContact = model.IsPrimaryContact;
                    context.SaveChanges();
                }
            }
        }
예제 #18
0
        public CallQueueCustomerEditModel GetCallQueueCustomerEditModel(CustomerContactViewModel model, bool isHealthPlanCallQueue)
        {
            var editModel = new CallQueueCustomerEditModel();

            editModel.CustomerId         = model.PatientInfomation.CustomerId.Value;
            editModel.ProspectCustomerId = model.PatientInfomation.ProspectCustomerId.HasValue ? model.PatientInfomation.ProspectCustomerId.Value : 0;
            editModel.FirstName          = model.PatientInfomation.FirstName;
            editModel.LastName           = model.PatientInfomation.LastName;
            editModel.Gender             = (int)model.PatientInfomation.Gender;
            editModel.Email               = model.PatientInfomation.Email;
            editModel.AlternateEmail      = model.PatientInfomation.AlternateEmail;
            editModel.UserId              = model.PatientInfomation.UserId;
            editModel.DateOfBirth         = model.PatientInfomation.DateOfBirth;
            editModel.CallId              = model.CallId;
            editModel.CallQueueCustomerId = model.PatientInfomation.CallQueueCustomerId;
            editModel.CallBackPhoneNumber = model.PatientInfomation.CallBackPhoneNumber.FormatPhoneNumber;
            editModel.OfficePhoneNumber   = model.PatientInfomation.OfficePhoneNumber.FormatPhoneNumber;
            editModel.MobilePhoneNumber   = model.PatientInfomation.MobilePhoneNumber.FormatPhoneNumber;
            editModel.IsHealthPlanQueue   = isHealthPlanCallQueue;
            editModel.Hicn = model.PatientInfomation.HicnNumber;
            editModel.Mbi  = model.PatientInfomation.MbiNumber;

            editModel.MemberId = model.PatientInfomation.MemberId;

            editModel.ActivityId = model.PatientInfomation.ActivityId;

            editModel.Address = new AddressEditModel
            {
                City               = model.PatientInfomation.AddressViewModel.City,
                CountryId          = 1,
                StateId            = model.PatientInfomation.AddressViewModel.StateId,
                StreetAddressLine1 = model.PatientInfomation.AddressViewModel.StreetAddressLine1,
                StreetAddressLine2 = model.PatientInfomation.AddressViewModel.StreetAddressLine2,
                ZipCode            = model.PatientInfomation.AddressViewModel.ZipCode
            };


            if (model.PatientInfomation.PrimaryCarePhysician != null)
            {
                editModel.PrimaryCarePhysician = new Core.Medical.ViewModels.PrimaryCarePhysicianEditModel
                {
                    FullName = model.PatientInfomation.PrimaryCarePhysician.FullName,
                    Address  = model.PatientInfomation.PrimaryCarePhysician.Address == null ? new AddressEditModel()
                    {
                        CountryId = 1
                    } : new AddressEditModel
                    {
                        City               = model.PatientInfomation.PrimaryCarePhysician.Address.City,
                        CountryId          = 1,
                        StreetAddressLine1 = model.PatientInfomation.PrimaryCarePhysician.Address.StreetAddressLine1,
                        StreetAddressLine2 = model.PatientInfomation.PrimaryCarePhysician.Address.StreetAddressLine2,
                        ZipCode            = model.PatientInfomation.PrimaryCarePhysician.Address.ZipCode,
                        StateId            = model.PatientInfomation.PrimaryCarePhysician.Address.StateId
                    },

                    MailingAddress = model.PatientInfomation.PrimaryCarePhysician.MailingAddress == null ? new AddressEditModel()
                    {
                        CountryId = 1
                    } : new AddressEditModel
                    {
                        City               = model.PatientInfomation.PrimaryCarePhysician.MailingAddress.City,
                        CountryId          = 1,
                        StreetAddressLine1 = model.PatientInfomation.PrimaryCarePhysician.MailingAddress.StreetAddressLine1,
                        StreetAddressLine2 = model.PatientInfomation.PrimaryCarePhysician.MailingAddress.StreetAddressLine2,
                        ZipCode            = model.PatientInfomation.PrimaryCarePhysician.MailingAddress.ZipCode,
                        StateId            = model.PatientInfomation.PrimaryCarePhysician.MailingAddress.StateId
                    },
                    Email          = model.PatientInfomation.PrimaryCarePhysician.Email,
                    Phone          = model.PatientInfomation.PrimaryCarePhysician.Phone,
                    HasSameAddress = model.PatientInfomation.PrimaryCarePhysician.HasSameAddress
                };
            }

            editModel.EnableEmail = model.PatientInfomation.EnableEmail;
            return(editModel);
        }
예제 #19
0
        public ActionResult ImportCustomerContacts(HttpPostedFileBase postedFile)
        {
            try
            {
                string filePath = string.Empty;
                if (postedFile != null)
                {
                    string path = Server.MapPath("~/ImportCustomerContacts/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    filePath = path + Path.GetFileName(postedFile.FileName);
                    string extension = Path.GetExtension(postedFile.FileName);
                    postedFile.SaveAs(filePath);

                    DataTable dtToExport = new DataTable();
                    int       cnt        = 0;
                    using (StreamReader sr = new StreamReader(filePath))
                    {
                        while (!sr.EndOfStream)
                        {
                            //string[] col = sr.ReadLine().Split(',');
                            string[] col = Regex.Split(sr.ReadLine(), ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)");
                            DataRow  dr  = dtToExport.NewRow();
                            if (col.Length > 0)
                            {
                                for (int i = 0; i < col.Length; i++)
                                {
                                    if (cnt == 0)
                                    {
                                        DataColumn dc = new DataColumn();
                                        dc.ColumnName = col[i].ToString();
                                        dtToExport.Columns.Add(dc);
                                    }
                                    else
                                    {
                                        dr[i] = col[i].ToString();
                                    }
                                }

                                if (cnt > 0)
                                {
                                    dtToExport.Rows.Add(dr);
                                }
                                if (cnt == 0)
                                {
                                    cnt++;
                                }
                            }
                        }
                    }


                    string[] columnNames = dtToExport.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToArray();
                    if (columnNames[0] != "Customer Name" && columnNames[1] != "Customer Contact" && columnNames[2] != "Contact Phone" && columnNames[3] != "Contact Email")
                    {
                        ViewBag.Message = "CSV file not in correct format. Please select valid CSV file and try again!";
                        return(View("ManageCustomerContacts"));
                    }
                    CustomerRepository _respository = new CustomerRepository();
                    for (int i = 0; i < dtToExport.Rows.Count; i++)
                    {
                        CustomerViewModel cst = new CustomerViewModel();
                        cst.CustomerName = dtToExport.Rows[i][0].ToString().Replace(@"""", "");

                        cst.InActive = false;
                        cst.Notes    = "";

                        int CustomerId;
                        CustomerId = _respository.AddUpdateCustomerImport(cst);
                        // Call SaveActivityLog("frmImportCustomers", "Import Customer", "Customer " + cst.CustomerName + " added from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + ".")
                        var act = new ActivityRepository();
                        act.AddActivityLog(Convert.ToString(Session["User"]), "Import Customer", "ImportCustomerContacts", "Customer " + cst.CustomerName + " added from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + ".");
                        if (dtToExport.Rows[i][1].ToString() != "" && dtToExport.Rows[i][2].ToString() != " && dtToExport.Rows[i][3].ToString() != ")
                        {
                            CustomerContactViewModel cstAdd = new CustomerContactViewModel();
                            cstAdd.CustomerId       = CustomerId;
                            cstAdd.CustomerContact  = dtToExport.Rows[i][1].ToString();
                            cstAdd.ContactPhone     = dtToExport.Rows[i][2].ToString();
                            cstAdd.ContactEmail     = dtToExport.Rows[i][3].ToString();
                            cstAdd.IsPrimaryContact = false;
                            // cstAdd.DateAdded = System.DateTime.Now;
                            CommonFunctions c = new CommonFunctions();
                            cstAdd.DateAdded = c.GetCurrentDate();

                            _respository.AddUpdateCustomerContact(cstAdd, "Add");
                            act = new ActivityRepository();
                            act.AddActivityLog(Convert.ToString(Session["User"]), "Import Customer Contacts", "ImportCustomer", "Contacts added for customer " + cst.CustomerName + " from csv file " + postedFile.FileName + " by user " + Convert.ToString(Session["User"]) + ".");
                        }
                    }
                }
                else
                {
                    ViewBag.Message = "Please select file to import";
                }

                return(View("ManageCustomerContacts"));
            }
            catch (Exception ex)
            {
                ViewBag.Message = "CSV file not in correct format. Please select valid CSV file and try again!";
                return(View("ManageCustomerContacts"));
            }
        }