public IHttpActionResult GetAllTaskTypes()
        {
            var repository = new RepositoryLookups();
            var response   = repository.GetAllTaskTypes(CurrentBusinessId);

            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
        public IHttpActionResult GetPracticeSpecialities()
        {
            var repository = new RepositoryLookups();
            var response   = repository.GetPractiesSpecialities();

            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetAllServicesByBusiness(int repId = 0)
        {
            var repository = new RepositoryLookups();
            var response   = repository.GetAllServices(CurrentBusinessId.Value, CurrentUserId, IsSalesManager, IsSalesDirector, IsRep, IsBuzAdmin);

            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
        public IHttpActionResult GetAllProviders(string searchKey = "")
        {
            var repository = new RepositoryLookups();
            var response   = repository.GetAllProviders(CurrentBusinessId, CurrentUserId, IsSalesManager, IsSalesDirector, IsRep, searchKey);

            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
        public IHttpActionResult GetAllmarketingCategories()
        {
            var repository = new RepositoryLookups();
            var response   = repository.GetAllmarketingCategories(CurrentBusinessId.Value);

            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
Ejemplo n.º 6
0
        public IHttpActionResult GetAllLeadSources()
        {
            var repository = new RepositoryLookups();
            var response   = repository.GetAllLeadSources();

            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
Ejemplo n.º 7
0
        public IHttpActionResult GetAllManagers()
        {
            DataResponse <EntityList <EntitySelectItem> > response = new DataResponse <EntityList <EntitySelectItem> >();
            RepositoryLookups repositoryLookup = new RepositoryLookups();

            response = repositoryLookup.GetAllMangers(CurrentBusinessId);
            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
Ejemplo n.º 8
0
        public IHttpActionResult GetAllTaskUsers(int?[] repGroupIds)
        {
            var repository = new RepositoryLookups();
            DataResponse <EntityList <EntitySelectItem> > response = new DataResponse <EntityList <EntitySelectItem> >();

            response = repository.GetAllTaskUsers(CurrentUser.BusinessId, CurrentUser.Id, IsRep, IsSalesManager, IsBuzAdmin, IsSalesDirector);
            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
Ejemplo n.º 9
0
        public IHttpActionResult GetAllRepsBySameGroup(int?[] repGroupIds)
        {
            var repository = new RepositoryLookups();
            DataResponse <EntityList <EntitySelectItem> > response = new DataResponse <EntityList <EntitySelectItem> >();

            response = repository.GetAllRepsByGroupId(repGroupIds, CurrentUser.BusinessId, CurrentUser.Id, !CurrentUser.Roles.Contains("BusinessAdmin"), IsSalesDirector);
            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
Ejemplo n.º 10
0
        public IHttpActionResult GetAllRepGroups()
        {
            string[] privileges = { "RDREPGRPALL" };
            if ((!IsBuzAdmin && !IsSalesManager) && (IsRep || !HasRight(privileges)))
            {
                return(Ok <DataResponse>(new DataResponse {
                    Message = "Access denied!", Status = DataResponseStatus.BadRequest
                }));
            }

            var repository = new RepositoryLookups();
            var response   = repository.GetAllRepGroups(CurrentUser.BusinessId, CurrentUserId, IsBuzAdmin, IsSalesManager, IsSalesDirector);

            return(Ok <DataResponse <EntityList <EntitySelectItem> > >(response));
        }
Ejemplo n.º 11
0
        public IHttpActionResult GetAllTaskPriorities(int serviceid)
        {
            var repository = new RepositoryLookups();

            var lookupSales = new LookupModels();

            lookupSales.Providers = repository.GetAllProviders(CurrentBusinessId, CurrentUserId, IsSalesManager, IsSalesDirector, IsRep).Model; //repository.GetProvidersByServiceId(serviceid, CurrentBusinessId).Model;
            lookupSales.Groups    = repository.GetAllRepGroups(CurrentBusinessId, CurrentUserId, IsBuzAdmin, IsRep, IsSalesManager).Model;
            lookupSales.Reps      = repository.GetAllReps(CurrentBusinessId, CurrentUserId, IsBuzAdmin, IsRep, IsSalesManager).Model;

            var response = new DataResponse <LookupModels>();

            response.Model = lookupSales;

            return(Ok <DataResponse <LookupModels> >(response));
        }
        public IHttpActionResult GetDashboardSalesDateType(int serviceId = 0)
        {
            var repository = new RepositoryStatistics();
            var response   = new EntityList <EntitySelectItem>();

            if (serviceId != 0)
            {
                this.ServiceId = serviceId;
                if (this.MapperFilePath == null)
                {
                    var    model       = response.List = null;
                    string serviceName = new RepositoryLookups().GetServiceNameById(this.ServiceId).Replace(" ", "");
                    var    error       = string.Format("XML mapper file is missing for the service \"{0}\"", serviceName);
                    return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, model = model, Message = error }));
                }
                repository.XmlMapper = XDocument.Load(this.MapperFilePath);
                var reportStaticColumns = repository.ReportStaticColumnsByAttribute("SummaryFilter");
                response.List = new List <EntitySelectItem>();
                foreach (var item in reportStaticColumns)
                {
                    response.List.Add(new EntitySelectItem {
                        Value = item.ColumnName, Text = item.DisplayName
                    });
                }
                return(Ok(response));
            }
            else if (CurrentBusinessId == 6)
            {
                response.List.Add(new EntitySelectItem {
                    Value = "ReceivedDate", Text = "Received Date", IsSelected = true
                });
                response.List.Add(new EntitySelectItem {
                    Value = "ReportedDate", Text = "Reported Date"
                });
                response.List.Add(new EntitySelectItem {
                    Value = "BilledDate", Text = "Billed Date"
                });
                response.List.Add(new EntitySelectItem {
                    Value = "PaidDate", Text = "Paid Date"
                });

                return(Ok(response));
            }
            return(Ok <DataResponse>(null));
        }
Ejemplo n.º 13
0
        public IHttpActionResult InsertTaskData(EntityTask model)
        {
            var response = new DataResponse <EntityTask>();
            var TaskId   = 0;

            if (ModelState.IsValid)
            {
                model.UpdatedBy         = model.CreatedBy = model.CurrentUserId = CurrentUserId;
                model.CurrentBusinessId = CurrentBusinessId;
                model.CreatedByName     = string.Format("{0} {1}", CurrentUser.FirstName, CurrentUser.LastName);

                if (model.TaskId > 0)
                {
                    var updateResponse = new RepositoryTask().Update(model);
                    if (updateResponse.Status == DataResponseStatus.OK)
                    {
                        TaskId = (int)updateResponse.Id;
                    }
                }
                else
                {
                    response = new RepositoryTask().Insert(model);
                    TaskId   = response.Model.TaskId;

                    #region Send email to users in assigned to and watchers list

                    try
                    {
                        var    rootPath     = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
                        var    ReturnUrl    = ConfigurationManager.AppSettings["PortalUrl"] + CurrentUser.BusinessName.Replace(" ", "-") + "#/tasks/" + response.Model.ReferenceNumber;
                        var    Subject      = "Task " + response.Model.ReferenceNumber + " - " + response.Model.Subject + "";
                        var    mail         = new GMEmail();
                        string toEmails     = null,
                               practiceName = null,
                               priorityType = null,
                               targetDate   = null;
                        if (model.PracticeId.HasValue)
                        {
                            practiceName = new RepositoryLookups().GetPracticeNameById(model.PracticeId.Value);
                        }
                        if (model.PriorityTypeId.HasValue)
                        {
                            priorityType = EnumHelper.GetEnumName <TaskPriorities>(model.PriorityTypeId.Value);
                        }
                        targetDate = model.TargetDate.HasValue ? model.TargetDate.ToString() : "Not Set";

                        foreach (var item in response.Model.AssignedUsersList)
                        {
                            if (item.UserId == CurrentUserId)
                            {
                                continue;
                            }

                            var emailBody = TemplateManager.NewTask(rootPath, item.Name, "", model.CreatedByName, model.Subject, targetDate, model.TaskDescription, practiceName, priorityType, ReturnUrl, false, CurrentBusinessId.Value, CurrentUser.RelativeUrl);
                            try
                            {
                                toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKASSGN");
                                if (!string.IsNullOrEmpty(toEmails))
                                {
                                    mail.SendDynamicHTMLEmail(item.Email, Subject, emailBody, CurrentUser.OtherEmails);
                                }
                            }
                            catch (Exception ex)
                            {
                                ex.Log();
                            }
                        }

                        foreach (var item in response.Model.WatchersList)
                        {
                            if (item.UserId == CurrentUserId)
                            {
                                continue;
                            }

                            var AssignedUsers = string.Join(",", response.Model.AssignedUsersList.Select(a => a.Name));

                            var emailBody = TemplateManager.NewTask(rootPath, item.Name, AssignedUsers, model.CreatedByName, model.Subject, targetDate, model.TaskDescription, practiceName, priorityType, ReturnUrl, true, CurrentBusinessId.Value, CurrentUser.RelativeUrl);
                            try
                            {
                                toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKCC");
                                if (!string.IsNullOrEmpty(toEmails))
                                {
                                    mail.SendDynamicHTMLEmail(item.Email, Subject, emailBody, CurrentUser.OtherEmails);
                                }
                            }
                            catch (Exception ex)
                            {
                                ex.Log();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.Log();
                    }

                    #endregion
                }

                #region Upload file

                if (model.Files != null && model.Files.Count > 0)
                {
                    List <string> FilesList = new List <string>();

                    foreach (var file in model.Files)
                    {
                        string FileName = SaveFile(file.Base64, file.FileName, TaskId);
                        FilesList.Add(FileName);
                    }

                    bool isImagesSaved = new RepositoryTask().SaveFiles(FilesList, TaskId, model.TaskId > 0);
                }

                #endregion

                response = new RepositoryTask().GetTaskById(TaskId, CurrentUserId, CurrentBusinessId, true);

                return(Ok <DataResponse>(response));
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
        }
Ejemplo n.º 14
0
        private void SendEmailNotification(string returnUrl, int taskId)
        {
            var        repository = new RepositoryTask(); var objTask = repository.GetTaskById(taskId, CurrentUserId, CurrentBusinessId);
            EntityTask model         = objTask.Model;
            var        CreatedByName = CurrentUser.FirstName + " " + CurrentUser.LastName;
            var        ReturnUrl     = ConfigurationManager.AppSettings["BaseUrl"] + CurrentUser.BusinessName.Replace(" ", "-") + "#/tasks/" + model.ReferenceNumber;
            var        rootPath      = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
            var        Subject       = "Task " + model.ReferenceNumber + " - " + model.Subject + "";
            var        mail          = new GMEmail();
            string     toEmails      = null,
                       practiceName  = null,
                       priorityType  = null,
                       targetDate    = null,
                       status        = null;

            if (model.PracticeId.HasValue)
            {
                practiceName = new RepositoryLookups().GetPracticeNameById(model.PracticeId.Value);
            }
            if (model.PriorityTypeId.HasValue)
            {
                priorityType = EnumHelper.GetEnumName <TaskPriorities>(model.PriorityTypeId.Value);
            }
            targetDate = model.TargetDate.HasValue ? model.TargetDate.ToString() : "Not Set";
            var AssignedUsers = string.Join(",", model.AssignedUsersList.Select(a => a.Name));

            if (!string.IsNullOrEmpty(returnUrl))
            {
                returnUrl += model.ReferenceNumber;
            }

            if (model.StatusId.HasValue)
            {
                status = Regex.Replace(EnumHelper.GetEnumName <TaskStatuses>(model.StatusId.Value), "([A-Z]{1,2}|[0-9]+)", " $1").Trim();
            }

            if (CurrentUserId != model.RequestedUser.UserId)
            {
                var emailBody = TemplateManager.UpdateOrDeleteTask(rootPath, model.RequestedUser.Name, null, CreatedByName, model.Subject,
                                                                   targetDate, model.TaskDescription, practiceName, priorityType, status, ReturnUrl, false, CurrentBusinessId.Value, CurrentUser.RelativeUrl);
                mail.SendDynamicHTMLEmail(model.RequestedUser.Email, Subject, emailBody, CurrentUser.OtherEmails);
            }

            foreach (var item in model.AssignedUsersList)
            {
                if (item.UserId == CurrentUserId)
                {
                    continue;
                }

                toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKSTATNFN");
                if (!string.IsNullOrEmpty(toEmails))
                {
                    var emailBody = TemplateManager.UpdateOrDeleteTask(rootPath, item.Name, null, CreatedByName, model.Subject,
                                                                       targetDate, model.TaskDescription, practiceName, priorityType, status, ReturnUrl, false, CurrentBusinessId.Value, CurrentUser.RelativeUrl);
                    mail.SendDynamicHTMLEmail(toEmails, Subject, emailBody, CurrentUser.OtherEmails);
                }
            }

            foreach (var item in model.WatchersList)
            {
                toEmails = new RepositoryUserProfile().NotificationEnabledEmails(item.Email, "TSKSTATNFN");
                if (!string.IsNullOrEmpty(toEmails))
                {
                    var emailBody = TemplateManager.UpdateOrDeleteTask(rootPath, item.Name, AssignedUsers, CreatedByName, model.Subject,
                                                                       targetDate, model.TaskDescription, practiceName, priorityType, status, ReturnUrl, true, CurrentBusinessId.Value, CurrentUser.RelativeUrl);
                    mail.SendDynamicHTMLEmail(toEmails, Subject, emailBody, CurrentUser.OtherEmails);
                }
            }
        }
Ejemplo n.º 15
0
        public IHttpActionResult ParseExcel(EntitySales model)
        {
            try
            {
                #region Upload file, Save records to database

                this.IsFinanceFile = model.IsFinanceFile;

                if (!HasRight(new string[] { "SLSIMPRT" }))
                {
                    return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = new { Message = "Unauthorized Operation" } }));
                }

                DataResponse response = new DataResponse();

                if (model.Files != null && model.Files.Count > 0)
                {
                    StringBuilder logString = new StringBuilder();
                    string        logPath   = HttpContext.Current.Server.MapPath(Path.Combine("~/Assets", CurrentBusinessId.Value.ToString(), "Sales", "Sales-Archives", "Uploads", "Logs"));
                    if (!Directory.Exists(logPath))
                    {
                        Directory.CreateDirectory(logPath);
                    }
                    string logFilePath = Path.Combine(logPath, string.Format("{0}.txt", DateTime.Now.ToString("MMddyyhhmmssttfff")));

                    if (!File.Exists(logFilePath))
                    {
                        FileStream fs = File.Create(logFilePath);
                        fs.Dispose();
                    }

                    logString.AppendLine("Parsing starts @ " + DateTime.Now);
                    logString.AppendLine("BusinessId \t:\t" + CurrentBusinessId.Value);

                    List <FileInfo> FilesList   = new List <FileInfo>();
                    string          serviceName = new RepositoryLookups().GetServiceNameById(model.ServiceId);

                    foreach (var file in model.Files)
                    {
                        string FileName = SaveFile(file.Base64, file.FileName, serviceName);
                        FilesList.Add(new FileInfo
                        {
                            SavedFileName    = FileName,
                            IncomingFileName = file.FileName
                        });
                    }

                    logString.AppendLine(string.Format("Total Files \t:\t{0}\t\nService Id \t:\t{1}", FilesList.Count(), model.ServiceId));

                    foreach (var fileInfo in FilesList)
                    {
                        XmlHelper xmlHelper = new XmlHelper();

                        string uploadPath   = Path.Combine(CurrentBusinessId.Value.ToString(), "Sales", "Sales-Archives", "Uploads", serviceName, fileInfo.SavedFileName);
                        string excelFile    = HttpContext.Current.Server.MapPath(Path.Combine("~/Assets", uploadPath));
                        string importedPath = Path.Combine("Assets", uploadPath);
                        this.ServiceId = model.ServiceId;

                        if (this.MapperFilePath == null)
                        {
                            logString.Append(string.Format("XML mapper file is missing for the service \"{0}\"", serviceName));
                            continue;
                        }
                        xmlHelper.XmlMapper = XDocument.Load(this.MapperFilePath);

                        int RecordCount;

                        xmlHelper.xmlString = new ExcelToXml().GetXMLString(excelFile, true, out RecordCount);

                        logString.AppendLine(string.Format("File Name \t:\t{0} \t Starts @{1}", fileInfo.SavedFileName, DateTime.UtcNow));

                        using (System.IO.StreamWriter logWriter = new System.IO.StreamWriter(logFilePath))
                        {
                            logWriter.WriteLine(logString);
                            logString.Clear();
                            int importSummeryId;
                            response = new RepositorySales().Insert(xmlHelper, RecordCount, CurrentBusinessId, CurrentUserId, model.ServiceId, IsFinanceFile, out importSummeryId, logWriter, "Web Upload", importedPath, fileInfo.IncomingFileName);
                            logString.AppendLine("File Successfully Processed");
                            logString.AppendLine("File moved to :" + excelFile);
                            logWriter.WriteLine(logString);
                        }
                    }
                    new Exception(logString.ToString()).Log(logFilePath, true);
                }

                HttpRuntime.Cache[CurrentUserId.ToString()] = true;
                return(Ok <DataResponse>(response));

                #endregion
            }
            catch (Exception ex)
            {
                ex.Log();
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = new { Message = string.Format("{0}|{1}", ex.Message, ex.InnerException != null ? ex.InnerException.Message : "") } }));
            }
        }
Ejemplo n.º 16
0
        public IHttpActionResult InsertLeadData(VMLead model)
        {
            List <string> adddress = new List <string>()
            {
                "model.PracticeAddressLine1",
                "model.City",
                "model.StateId",
                "model.Zip",
                "model.PhoneNumber"
            };

            List <string> reporrepgroup = null;

            bool hasAnyAddressFields = adddress.Any(a => ModelState.IsValidField(a)),
                 hasAllAddressFields = adddress.All(a => ModelState.IsValidField(a));

            if (!HasRight(new string[] { "WRREP" }) && IsRep)
            {
                ModelState["model.RepId"].Errors.Clear();
                ModelState["model.RepGroupId"].Errors.Clear();
            }
            else
            {
                reporrepgroup = new List <string>()
                {
                    "model.RepId",
                    "model.RepGroupId"
                };
            }

            if (hasAnyAddressFields && !hasAllAddressFields)
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }

            var isRepandRepgroupSelected = reporrepgroup != null && reporrepgroup.Any(a => ModelState.IsValidField(a));

            if (!isRepandRepgroupSelected)
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any() && reporrepgroup.Contains(a.Key)).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }

            var repository = new RepositoryLead();
            var response   = new DataResponse <EntityLead>();

            if (!string.IsNullOrEmpty(model.PracticeName))
            {
                #region Fully Valid

                var entityLead = new EntityLead
                {
                    LeadSourceId       = model.LeadSourceId,
                    LeadServiceIntrest = model.ServiceInterest,
                    IsActive           = true,
                    RepGroupId         = model.RepGroupId,
                    RepId = model.RepId,
                    ContactPreferenceId = 1,
                    OtherLeadSource     = model.OtherLeadSource,
                    IsConverted         = false,
                };

                entityLead.Practice = new EntityPractice
                {
                    Name             = model.PracticeName,
                    SpecialityTypeId = model.SpecialityTypeId,
                    //Fax = model.Fax
                };

                if (hasAllAddressFields)
                {
                    //entityLead.Practice.Fax = model.Fax;
                    entityLead.Practice.Address = new List <EntityPracticeAddress> {
                        new EntityPracticeAddress {
                            Id            = model.AddressId == null ? 0 : model.AddressId.Value,
                            AddressIndex  = -1,
                            City          = model.City,
                            Line1         = model.PracticeAddressLine1,
                            Line2         = model.PracticeAddressLine2,
                            AddressTypeId = 1,
                            StateId       = model.StateId ?? 0,
                            Zip           = model.Zip,
                            Fax           = model.Fax,
                            Phone         = new List <EntityPracticePhone> {
                                new EntityPracticePhone {
                                    PhoneNumber = model.PhoneNumber,
                                    Extension   = model.PhoneExtension
                                }
                            }
                        }
                    };
                }

                entityLead.Practice.Specialities = new List <EntityPracticeSpeciality>();
                var specialities = new List <EntityPracticeSpeciality>();

                entityLead.PracticeTypeId = model.SpecialityTypeId == 0 ? null : model.SpecialityTypeId;
                if (model.SpecialityTypeId == 1)
                {
                    specialities.Add(new EntityPracticeSpeciality {
                        PracticeSpecialityId = model.SpecialityId ?? 0
                    });
                }
                else if (model.SpecialityTypeId == 2 && model.SpecialityIds != null && model.SpecialityIds.Count() > 0)
                {
                    foreach (string sId in model.SpecialityIds)
                    {
                        specialities.Add(new EntityPracticeSpeciality {
                            PracticeSpecialityId = int.Parse(sId)
                        });
                    }
                }
                else if (model.SpecialityTypeId == 3 && !string.IsNullOrEmpty(model.NewSpectialityName))
                {
                    entityLead.Practice.SpecialityType = model.NewSpectialityName;
                }
                if (specialities.Count > 0)
                {
                    entityLead.Practice.Specialities = specialities;
                }

                #region Save Location
                if (model.Locations != null && model.Locations.Count() > 0)
                {
                    var addressList = new List <EntityPracticeAddress>();

                    model.Locations.ForEach(a => addressList.Add(new EntityPracticeAddress
                    {
                        Id            = a.AddressId == null ? 0 : a.AddressId.Value,
                        AddressIndex  = a.AddressIndex.Value,
                        City          = a.City,
                        Line1         = a.AddressLine1,
                        Line2         = a.AddressLine2,
                        AddressTypeId = 2,
                        StateId       = a.StateId ?? 0,
                        Zip           = a.Zip,
                        ManagerName   = a.ManagerName,
                        Phone         = new List <EntityPracticePhone> {
                            new EntityPracticePhone {
                                PhoneNumber = a.PhoneNumber,
                                Extension   = a.Extension
                            }
                        }
                    }));

                    if (addressList.Count > 0)
                    {
                        entityLead.Practice.Address = entityLead.Practice.Address.Concat(addressList);
                    }
                }
                #endregion

                #region Save Providers

                if (hasAnyAddressFields && hasAllAddressFields)
                {
                    if (model.Providers != null && model.Providers.Count() > 0)
                    {
                        var isMultipleProviders = model.Providers.GroupBy(a => a.NPI).Any(a => a.Count() > 1);
                        if (isMultipleProviders)
                        {
                            return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = new { Key = "NPI", Message = "NPI is Repeating" } }));
                        }

                        var providerList = new List <EntityProvider>();

                        model.Providers.ForEach(a =>
                                                providerList.Add(
                                                    new EntityProvider
                        {
                            Id           = a.Id == null ? 0 : a.Id.Value,
                            DegreeId     = a.DegreeId ?? 0,
                            FirstName    = a.FirstName,
                            LastName     = a.LastName,
                            MiddleName   = a.MiddleName,
                            NPI          = a.NPI,
                            AddressIndex = a.Location != null ? (a.Location.AddressIndex == null ? -1 : a.Location.AddressIndex.Value) : -1,
                            Address      = a.Location != null ? new EntityProviderAddress
                            {
                                Id            = a.Location.AddressId == null ? 0 : a.Location.AddressId.Value,
                                City          = a.Location.City,
                                Line1         = a.Location.AddressLine1,
                                Line2         = a.Location.AddressLine2,
                                AddressTypeId = 2,
                                StateId       = a.Location.StateId.Value,
                                Zip           = a.Location.Zip,
                                ManagerName   = a.Location.ManagerName,
                                Phone         = a.Location == null ? null : new List <EntityPracticePhone> {
                                    new EntityPracticePhone {
                                        PhoneNumber = a.Location.PhoneNumber,
                                        Extension   = a.Location.Extension
                                    }
                                }
                            } : null
                        }));

                        if (providerList.Count > 0)
                        {
                            entityLead.Practice.Providers = providerList;
                        }
                    }
                }
                #endregion

                entityLead.UpdatedBy     = entityLead.CreatedBy = entityLead.CurrentUserId = CurrentUser.Id;
                entityLead.BusinessId    = CurrentUser.BusinessId;
                entityLead.CreatedByName = string.Format("{0} {1}", CurrentUser.FirstName, CurrentUser.LastName);

                if (model.Id > 0)
                {
                    entityLead.LeadId = model.Id ?? 0;
                    response          = repository.Update(entityLead);
                }
                else
                {
                    string services = string.Empty, providers = string.Empty, practiceAddress = string.Empty;

                    response = repository.Insert(entityLead);
                    var responseModel = response.Model;

                    if (responseModel.Practice.Providers != null && responseModel.Practice.Providers.Count() > 0)
                    {
                        foreach (var item in responseModel.Practice.Providers)
                        {
                            providers = providers + item.FirstName + " " + item.LastName + " (" + item.NPI + ") <br />";
                        }
                    }

                    var primaryAddress = responseModel.Practice.Address.FirstOrDefault();
                    if (primaryAddress != null)
                    {
                        var stateName = new RepositoryLookups().GetAllStates().Model.List.Where(a => a.Id == primaryAddress.StateId).First().Value;
                        practiceAddress = string.Format("{0}, {1}, {2}, {3}, {4}", primaryAddress.Line1, primaryAddress.Line2, primaryAddress.City, stateName, primaryAddress.Zip);
                    }

                    if (responseModel.LeadId > 0)
                    {
                        EmailNotification emailNotify = new EmailNotification
                        {
                            PracticeName         = model.PracticeName,
                            PracticeAddress      = practiceAddress,
                            Providers            = providers,
                            Services             = services,
                            RepFirstName         = responseModel.Rep.FirstName,
                            RepMiddleName        = responseModel.Rep.MiddleName,
                            RepLastName          = responseModel.Rep.LastName,
                            RepEmail             = responseModel.Rep.RepEmail,
                            Managers             = responseModel.Rep.Managers,
                            CurrentUserFirstName = CurrentUser.FirstName,
                            CurrentUserLastName  = CurrentUser.LastName,
                            RootPath             = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath,
                            ReturnUrl            = ConfigurationManager.AppSettings["BaseUrl"],
                        };
                        NewLeadEmailNotification(emailNotify);
                    }
                }

                #endregion
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
            return(Ok <DataResponse>(response));
        }
Ejemplo n.º 17
0
        public IHttpActionResult InsertAccountData(VMAccount model)
        {
            if (!IsRep && (model.RepId == null || model.RepId <= 0))
            {
                List <dynamic> errorList = new List <dynamic>();

                if (!HasRight(new string[] { "RDREPGRPALL" }))
                {
                    errorList.Add(new { Message = "You do not have right to read repgroup" });
                }

                if (!HasRight(new string[] { "WRREP" }))
                {
                    errorList.Add(new { Message = "You do not have right to create rep" });
                }

                if (errorList != null && errorList.Count <= 0)
                {
                    errorList.Add(new { Message = "RepGroup and Rep are required" });
                }

                return(Ok <dynamic>(new { Status = HttpStatusCode.PreconditionFailed, ResponseMessage = errorList }));
            }

            var repository = new RepositoryAccount();
            var response   = new DataResponse();

            if (ModelState.IsValid)
            {
                var entityAccount = new EntityAccount
                {
                    EnrolledDate       = model.EnrolledDate,
                    IsActive           = model.IsActive,
                    LeadSourceId       = model.LeadSourceId,
                    LeadServiceIntrest = model.ServiceInterest,
                    RepGroupId         = model.RepGroupId,
                    RepId       = model.RepId,
                    IsConverted = true,
                    ServiceIds  = model.EnrolledServices
                };
                entityAccount.Practice = new EntityPractice
                {
                    //Fax = model.Fax,
                    ReportDeliveryEmail = model.ReportDeliveryEmail,
                    ReportDeliveryFax   = model.ReportDeliveryFax,
                    Name                = model.PracticeName,
                    SpecialityTypeId    = model.SpecialityTypeId,
                    ContactPreferenceId = model.MethodOfContact,
                    Address             = new List <EntityPracticeAddress>
                    {
                        new EntityPracticeAddress {
                            Id            = model.AddressId ?? 0,
                            AddressIndex  = -1,
                            City          = model.City,
                            Line1         = model.PracticeAddressLine1,
                            Line2         = model.PracticeAddressLine2,
                            AddressTypeId = 1,
                            StateId       = model.StateId ?? 0,
                            Zip           = model.Zip,
                            Fax           = model.Fax,
                            Phone         = new List <EntityPracticePhone> {
                                new EntityPracticePhone {
                                    PhoneNumber = model.PhoneNumber,
                                    Extension   = model.PhoneExtension
                                }
                            },
                            AddressId           = model.AddressId ?? 0,
                            ManagerName         = model.ManagerName,
                            ManagerEmail        = model.ManagerEmail,
                            ManagerPhone        = model.ManagerPhone,
                            BillingContact      = model.BillingContact,
                            BillingContactEmail = model.BillingContactEmail,
                            BillingContactPhone = model.BillingContactPhone,
                            officedayshrs       = model.WorkingHours,
                        }
                    },
                    Contact = new List <EntityPracticeContact>
                    {
                        new EntityPracticeContact
                        {
                            BillingContact      = model.BillingContact,
                            BillingContactEmail = model.BillingContactEmail,
                            BillingContactPhone = model.BillingContactPhone,
                            ManagerName         = model.ManagerName,
                            ManagerPhone        = model.ManagerPhone,
                            ManagerEmail        = model.ManagerEmail,
                            officedayshrs       = model.WorkingHours,
                            AddressId           = model.AddressId ?? 0
                        }
                    }
                };

                var specialities = new List <EntityPracticeSpeciality>();

                entityAccount.Practice.Specialities = new List <EntityPracticeSpeciality>();
                entityAccount.PracticeTypeId        = model.SpecialityTypeId == 0 ? null : model.SpecialityTypeId;
                if (model.SpecialityTypeId == 1)
                {
                    specialities.Add(new EntityPracticeSpeciality {
                        PracticeSpecialityId = model.SpecialityId ?? 0
                    });
                }
                else if (model.SpecialityTypeId == 2 && model.SpecialityIds != null && model.SpecialityIds.Count() > 0)
                {
                    foreach (string sId in model.SpecialityIds)
                    {
                        specialities.Add(new EntityPracticeSpeciality {
                            PracticeSpecialityId = int.Parse(sId)
                        });
                    }
                }
                else if (model.SpecialityTypeId == 3 && !string.IsNullOrEmpty(model.NewSpectialityName))
                {
                    entityAccount.Practice.SpecialityType = model.NewSpectialityName;
                }

                if (specialities.Count > 0)
                {
                    entityAccount.Practice.Specialities = specialities;
                }

                if (model.Locations != null)
                {
                    var addressList = new List <EntityPracticeAddress>();
                    var contactList = new List <EntityPracticeContact>();
                    model.Locations.ToList().ForEach(a => addressList.Add(new EntityPracticeAddress
                    {
                        Id            = a.AddressId ?? 0,
                        AddressIndex  = a.AddressIndex.Value,
                        Line1         = a.AddressLine1,
                        Line2         = a.AddressLine2,
                        City          = a.City,
                        AddressTypeId = 2,
                        StateId       = a.StateId ?? 0,
                        Zip           = a.Zip,
                        Fax           = a.Fax,
                        Phone         = new List <EntityPracticePhone> {
                            new EntityPracticePhone {
                                PhoneNumber = a.PhoneNumber,
                                Extension   = a.Extension
                            }
                        },
                        AddressId           = a.AddressId ?? 0,
                        ManagerName         = a.ManagerName,
                        ManagerEmail        = a.ManagerEmail,
                        ManagerPhone        = a.ManagerPhone,
                        BillingContact      = a.BillingContact,
                        BillingContactEmail = a.BillingContactEmail,
                        BillingContactPhone = a.BillingContactPhone,
                        officedayshrs       = a.WorkingHours,
                    }));

                    if (addressList.Count > 0)
                    {
                        entityAccount.Practice.Address = entityAccount.Practice.Address.Concat(addressList);
                    }

                    entityAccount.Practice.Address.ToList().ForEach(a => contactList.Add(new EntityPracticeContact
                    {
                        AddressId           = a.AddressId,
                        ManagerName         = a.ManagerName,
                        ManagerEmail        = a.ManagerEmail,
                        ManagerPhone        = a.ManagerPhone,
                        BillingContact      = a.BillingContact,
                        BillingContactEmail = a.BillingContactEmail,
                        BillingContactPhone = a.BillingContactPhone,
                        officedayshrs       = a.officedayshrs,
                    }));

                    if (contactList.Count > 0)
                    {
                        entityAccount.Practice.Contact = contactList;
                    }
                }
                if (model.Providers != null)
                {
                    var isMultipleProviders = model.Providers.GroupBy(a => a.NPI).Any(a => a.Count() > 1);
                    if (isMultipleProviders)
                    {
                        return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = new { Key = "NPI", Message = "NPI is Repeating" } }));
                    }

                    var providerList = new List <EntityProvider>();
                    model.Providers.ForEach(a =>
                                            providerList.Add(
                                                new EntityProvider
                    {
                        Id           = a.Id ?? 0,
                        DegreeId     = a.DegreeId ?? 0,
                        FirstName    = a.FirstName,
                        LastName     = a.LastName,
                        MiddleName   = a.MiddleName,
                        NPI          = a.NPI,
                        AddressIndex = a.Location != null ? (a.Location.AddressIndex == null ? -1 : a.Location.AddressIndex.Value) : -1,
                        Address      = a.Location != null ? new EntityProviderAddress
                        {
                            Id            = a.Location.AddressId == null ? 0 : a.Location.AddressId.Value,
                            City          = a.Location.City,
                            Line1         = a.Location.AddressLine1,
                            Line2         = a.Location.AddressLine2,
                            AddressTypeId = 2,
                            StateId       = a.Location.StateId.Value,
                            Zip           = a.Location.Zip,
                            Fax           = a.Location.Fax,
                            ManagerName   = a.Location.ManagerName,
                            Phone         = a.Location == null ? null : new List <EntityPracticePhone> {
                                new EntityPracticePhone {
                                    PhoneNumber = a.Location.PhoneNumber,
                                    Extension   = a.Location.Extension
                                }
                            }
                        } : null
                    }));

                    if (providerList.Count > 0)
                    {
                        entityAccount.Practice.Providers = providerList;
                    }
                }
                entityAccount.UpdatedBy     = entityAccount.CreatedBy = entityAccount.CurrentUserId = CurrentUser.Id;
                entityAccount.BusinessId    = CurrentUser.BusinessId;
                entityAccount.CreatedByName = string.Format("{0} {1}", CurrentUser.FirstName, CurrentUser.LastName);

                if (model.Id > 0) //Update
                {
                    entityAccount.Id = model.Id ?? 0;
                    response         = repository.Update(entityAccount);
                }
                else
                {
                    if (model.LeadId > 0) //Converted from Lead
                    {
                        entityAccount.LeadId = model.LeadId;
                        response             = repository.ConvertToAccount(entityAccount);
                    }
                    else //New account
                    {
                        response = repository.Insert(entityAccount);
                    }

                    if (response.Id != null)
                    {
                        string services = string.Empty, providers = string.Empty, practiceAddress = string.Empty;

                        if (entityAccount.ServiceIds != null)
                        {
                            var ids = ((IEnumerable <string>)entityAccount.ServiceIds).Select(a => Convert.ToInt32(a)).ToArray();
                            services = string.Join(", ", new RepositoryLookups().GetServicesById(ids));
                        }

                        foreach (var item in entityAccount.Practice.Providers)
                        {
                            providers = providers + item.FirstName + " " + item.LastName + " (" + item.NPI + ") <br />";
                        }

                        var primaryAddress = entityAccount.Practice.Address.First();

                        var stateName = new RepositoryLookups().GetAllStates().Model.List.Where(a => a.Id == primaryAddress.StateId).First().Value;
                        practiceAddress = string.Format("{0}, {1}, {2}, {3}, {4}", primaryAddress.Line1, primaryAddress.Line2, primaryAddress.City, stateName, primaryAddress.Zip);

                        EntityGroupManagerDetails RepModel = repository.RepDetailsByAccountId(response.Id).Model;

                        EmailNotification emailNotify = new EmailNotification
                        {
                            PracticeName         = model.PracticeName,
                            PracticeAddress      = practiceAddress,
                            Providers            = providers,
                            Services             = services,
                            RepFirstName         = RepModel.RepFirstName,
                            RepMiddleName        = RepModel.RepMiddleName,
                            RepLastName          = RepModel.RepLastName,
                            RepEmail             = RepModel.RepEmail,
                            Managers             = RepModel.Managers,
                            CurrentUserFirstName = CurrentUser.FirstName,
                            CurrentUserLastName  = CurrentUser.LastName,
                            RootPath             = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath,
                            ReturnUrl            = ConfigurationManager.AppSettings["BaseUrl"],
                        };
                        NewAccountEmailNotification(emailNotify);
                    }
                }
            }
            else
            {
                var errorList = ModelState.Where(a => a.Value.Errors.Any()).Select(s => new
                {
                    Key     = s.Key.Split('.').Last(),
                    Message = s.Value.Errors[0].ErrorMessage
                });
                return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = errorList }));
            }
            return(Ok <DataResponse>(response));
        }