Example #1
0
        public JsonResult menu()
        {
            genericResponse _response = new genericResponse();

            try
            {
                // All "Page Menu Groups" and their "Page Menus"
                List <module_and_PageMenuGroup> _module_and_PageMenuGroup = myModulePageMenuGroups;

                #region [ if there are "Page Menu Groups" -> Return a set for a specific Module ]
                if (_module_and_PageMenuGroup != null)
                {
                    var q = from a in _module_and_PageMenuGroup
                            select a;

                    IEnumerable <iItemType> _myModulePageMenuGroups = q.Select(a => new rPageMenuGroup()
                    {
                        pageMenuGroupId = a.pageMenuGroup.pageMenuGroupId,
                        caption         = a.pageMenuGroup.caption,
                        description     = a.pageMenuGroup.description,
                        iconClass       = a.pageMenuGroup.iconClass,
                        defaultPage     = a.pageMenuGroup.DefaultPage,
                        pageMenus       = a.pageMenus
                    }).ToList();
                    _response = new genericResponse()
                    {
                        success = true, results = _myModulePageMenuGroups.ToList()
                    };
                }
                #endregion

                #region [ Otherwise, return an empty set ]
                else
                {
                    _response = new genericResponse()
                    {
                        success = true
                    }
                };
                #endregion

                JsonResult _result = Json(_response, JsonRequestBehavior.AllowGet);
                return(Json(_response, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                HttpContext.Response.StatusCode = 500;
                _response = new genericResponse {
                    success = false
                };
                return(Json(_response, JsonRequestBehavior.AllowGet));
            }
        }
        public genericResponse SaveCompany(TBL_COMPANIES _company)
        {
            genericResponse _response;
            try
            {
                int companiesId = _company.COMPANIESID;
                _company.IsActive = true;

                if (!VerifyCompanyRequiredFields(_company))
                    throw new Exception("Company required fields are not submiited");

                if (companiesId > 0)
                {
                    //Update Operation
                    _company.UpdatedBy = CurrentUser.UserId.ToString();
                    _company.UpdatedDate = DateTime.Now;
                    companiesId = uow.CompanyRepository().UpdateCompany(_company);
                }
                else
                {
                    List<CompanyView> companies = uow.CompanyRepository().Get("", "COMPANYNAME ASC", 0, 0,null, CurrentUser.FranchiseeID, false).ToList().Where(r => r.COMPANYNAME == _company.COMPANYNAME).ToList<CompanyView>();

                    if (companies.Count > 0)
                    {
                        _response = new genericResponse() { success = false, UniqueId = companies[0].COMPANIESID };
                        return _response;
                    }
                    //Add Operation
                    _company.CreatedDate = DateTime.Now;
                    _company.CreatedBy = CurrentUser.UserId.ToString();
                    companiesId = uow.CompanyRepository().AddCompany(_company);
                }
                uow.Save();
                //We will send back the companiesId - Either newly created or from Updated record
                _response = new genericResponse() { success = true, UniqueId = companiesId };
                return _response;
            }
            catch (Exception ex)
            {
                //_response = new genericResponse() { success = false, message = "There is a problem in Saving Company Information. Please try again later." };
                //return _response;
                throw new Exception("There is a problem in Saving Company Information. Please try again later.", ex);
            }
        }
        public genericResponse ArchiveContact(TBL_CONTACTS _contact)
        {
            genericResponse _response;
            try
            {
                if (uow.ContactRepository().ArchiveContact(_contact.CONTACTSID, CurrentUser.UserId.ToString()))
                {
                    _response = new genericResponse() { success = true };
                    return _response;
                }
                else
                {
                    _response = new genericResponse() { success = false, message = "There is a problem Archiving this Contact Record. Please try again later." };
                    return _response;
                }

            }
            catch
            {
                _response = new genericResponse() { success = false, message = "There is a problem Archiving this Contact Record. Please try again later." };
                return _response;
            }
        }
        public genericResponse SendMeetingInviteNow(SendMeetingInvite meetingInfo)
        {
            genericResponse _response;
            try
            {
                #region [[ Basic Check Here...]]
                if (meetingInfo != null
                    && !string.IsNullOrEmpty(meetingInfo.SUBJECT)
                    && !string.IsNullOrEmpty(meetingInfo.MESSAGE)
                    //To Address Option....
                    && (!string.IsNullOrEmpty(meetingInfo.RCPNTS) || CheckRecipientsExist(meetingInfo.userEmailGroups))
                    && CheckDateElements(meetingInfo))
                {

                    #region [[ Continue as we are good...]]
                    bool IsMessageSent = false;
                    string _file_path = "";
                    var sendEmails = Convert.ToBoolean(ConfigurationManager.AppSettings["General.SendBlastEmails"]);
                    //Let us gather Information for sending Email out...
                    var client = new SmtpClient();
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.UseDefaultCredentials"].ToString()))
                        client.UseDefaultCredentials = true;
                    client.Host = ConfigurationManager.AppSettings["Server.Hostname"].ToString();// "smtp.cso.local";
                    client.Port = int.Parse(ConfigurationManager.AppSettings["Server.Port"].ToString());//25;
                    //client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.CredentialsRequired"].ToString()))
                        client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Server.Username"].ToString(), ConfigurationManager.AppSettings["Server.Password"].ToString());
                    //Now set up MailMessage
                    MailMessage message = new MailMessage();
                    message.IsBodyHtml = true;
                    //From Address
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.CredentialsRequired"].ToString()))
                    {
                        message.From = new MailAddress("*****@*****.**");
                    }
                    else
                    {
                        message.From = new MailAddress(CurrentUser.EmailAdress);
                    }
                    //Subject
                    message.Subject = meetingInfo.SUBJECT.Trim();
                    //Meeting type and Recurrency Freq Type
                    string meetingType = uow.EmailRepository().GetMeetingTypeName(Convert.ToInt32(meetingInfo.TypeId));
                    string RecurrenceFrequency = "";
                    if (!string.IsNullOrEmpty(meetingInfo.FreqId))
                    {
                        RecurrenceFrequency = uow.EmailRepository().GetMeetingFreqTypeName(Convert.ToInt32(meetingInfo.FreqId));
                    }
                    //For HTML Body
                    string bodyText = "Meeting Type: {0}\r\n\r\n</br></br>{1}";
                    bodyText = string.Format(bodyText, meetingType, meetingInfo.MESSAGE.Trim().Replace("\r\n", "<br/>").Replace(" ", "&nbsp;"));
                    AlternateView body = AlternateView.CreateAlternateViewFromString(bodyText, new ContentType("text/html"));
                    message.AlternateViews.Add(body);

                    System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
                    //Check if event is Rercurring type
                    if (meetingInfo.IsRecurring == null || meetingInfo.IsRecurring == "1")
                    {
                        AlternateView avCal =
                            AlternateView.CreateAlternateViewFromString(CreateCalendarEvent(message.Subject,
                            meetingInfo.MESSAGE.Trim().Replace("\r\n", "<br/>").Replace(" ", "&nbsp;"),
                            GetDateAndTimeTogether(Convert.ToDateTime(meetingInfo.STARTDTE), meetingInfo.STARTTIME.ToString()),
                            GetDateAndTimeTogether(Convert.ToDateTime(meetingInfo.ENDDTE), meetingInfo.ENDTIME.ToString()),
                            meetingInfo.LOCATION.Trim(),
                            message.From.Address,
                            null,
                            false), ct);
                        message.AlternateViews.Add(avCal);
                    }
                    else
                    {
                        //For recurring Event...
                        AlternateView avCal = AlternateView.CreateAlternateViewFromString(CreateCalendarEvent(message.Subject,
                            meetingInfo.MESSAGE.Trim().Replace("\r\n", "<br/>").Replace(" ", "&nbsp;"),
                            GetDateAndTimeTogether(Convert.ToDateTime(meetingInfo.STARTDTE), meetingInfo.STARTTIME.ToString()),
                            Convert.ToDouble(meetingInfo.Duration),
                            meetingInfo.LOCATION.Trim(),
                            message.From.Address,
                            null,
                            false,
                            GetRecurrenceDayInterval(RecurrenceFrequency),
                            Convert.ToInt32(meetingInfo.RecurrenceCount),
                            RecurrenceFrequency), ct);
                        message.AlternateViews.Add(avCal);
                    }

                    //Set To Address as From by default
                    message.To.Add(message.From);
                    //For Entered Email Addresses
                    if (!string.IsNullOrEmpty(meetingInfo.RCPNTS))
                    {
                        //We also have email address entered here
                        string[] receiverAddress = meetingInfo.RCPNTS.Trim().Split(',');
                        foreach (string address in receiverAddress)
                        {
                            //Add Address as To
                            if (Validation.ValidateEmail(address.Trim()))
                            {
                                message.To.Add(new MailAddress(address.Trim()));
                            }
                        }
                    }
                    //For User Grooup if any selected .....
                    foreach (EmailGroups usrg in meetingInfo.userEmailGroups)
                    {
                        if (usrg.IsSelected)
                        {
                            emailAdrsInfo = null;
                            emailAdrsInfo = uow.EmailRepository().GetUserEmailGroupAddresses(Convert.ToInt32(usrg.Id)).ToList();
                            message = AddAddresses(emailAdrsInfo, message);
                        }
                    }

                    //For Attachement...
                    if (!string.IsNullOrEmpty(meetingInfo.FILENAMES))
                    {
                        //Now save the file in the tmp folder
                        _file_path = System.Web.Hosting.HostingEnvironment.MapPath("~");
                        if (_file_path.Substring(_file_path.Length) != "\\")
                        {
                            _file_path += "\\";
                        }
                        _file_path += "Uploads\\" + meetingInfo.FILENAMES;

                        using (System.IO.FileStream fileStream = new System.IO.FileStream(_file_path, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            System.Net.Mail.Attachment _attachment = new System.Net.Mail.Attachment(fileStream, meetingInfo.FILENAME, MediaTypeNames.Application.Octet);
                            // Add time stamp information for the file.
                            ContentDisposition disposition = _attachment.ContentDisposition;
                            disposition.CreationDate = System.IO.File.GetCreationTime(_file_path);
                            disposition.ModificationDate = System.IO.File.GetLastWriteTime(_file_path);
                            disposition.ReadDate = System.IO.File.GetLastAccessTime(_file_path);
                            // Add the file attachment to this e-mail message.
                            message.Attachments.Add(_attachment);

                            //Send the message with Attachment
                            if (sendEmails)
                            {
                                client.Timeout = 30000000;
                                client.Send(message);
                                IsMessageSent = true;
                            }
                        }
                        //Now delete attachment
                        File.Delete(_file_path);
                    }
                    //Send the message for non-Attachment Messages...
                    if (sendEmails && !IsMessageSent)
                    {
                        client.Timeout = 30000000;
                        client.Send(message);
                    }
                    #endregion
                    _response = new genericResponse() { success = true };

                }
                else
                {
                    _response = new genericResponse() { success = false, message = "Required information is missing. Please check and correct your entry to proceed." };
                }
                #endregion
                //Back
                return _response;
            }
            catch (Exception ex)
            {
                _response = new genericResponse() { success = false, message = "There is a problem in sending the Email message. Please try again later. " + ex.Message };
                return _response;
            }
        }
        public genericResponse Save(SendEmailInfo emailInfo)
        {
            genericResponse _response;
            try
            {
                #region [[ Basic Check Here...]]
                if (emailInfo != null
                    && !string.IsNullOrEmpty(emailInfo.SUBJECT)
                    && !string.IsNullOrEmpty(emailInfo.MESSAGE)
                    //To Address Option....
                    && (!string.IsNullOrEmpty(emailInfo.RCPNTS) || CheckRecipientsExist(emailInfo.userEmailGroups) || CheckRecipientsExist(emailInfo.blastEmailGroups)))
                {
                    #region [[ Continue as we are good...]]
                    bool IsMessageSent = false;
                    string _file_path = "";
                    var sendEmails = Convert.ToBoolean(ConfigurationManager.AppSettings["General.SendBlastEmails"]);
                    //Let us gather Information for sending Email out...
                    var client = new SmtpClient();
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.UseDefaultCredentials"].ToString()))
                        client.UseDefaultCredentials = true;
                    client.Host = ConfigurationManager.AppSettings["Server.Hostname"].ToString();// "smtp.cso.local";
                    client.Port = int.Parse(ConfigurationManager.AppSettings["Server.Port"].ToString());//25;
                    //client.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.CredentialsRequired"].ToString()))
                        client.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["Server.Username"].ToString(), ConfigurationManager.AppSettings["Server.Password"].ToString());
                    //Now set up MailMessage
                    MailMessage message = new MailMessage();
                    message.IsBodyHtml = true;
                    //From Address
                    if (Convert.ToBoolean(ConfigurationManager.AppSettings["Server.CredentialsRequired"].ToString()))
                    {
                        message.From = new MailAddress("*****@*****.**");
                    }
                    else
                    {
                        message.From = new MailAddress(CurrentUser.EmailAdress);
                    }
                    //Subject
                    message.Subject = emailInfo.SUBJECT.Trim();
                    message.Body = emailInfo.MESSAGE.Trim().Replace("\r\n", "<br/>").Replace(" ", "&nbsp;");
                    //Set To Address as From by default
                    message.To.Add(message.From);
                    //For Entered Email Addresses
                    if (!string.IsNullOrEmpty(emailInfo.RCPNTS))
                    {
                        //We also have email address entered here
                        string[] receiverAddress = emailInfo.RCPNTS.Trim().Split(',');
                        foreach (string address in receiverAddress)
                        {
                            //Add Address as To
                            if (Validation.ValidateEmail(address.Trim()))
                            {
                                message.To.Add(new MailAddress(address.Trim()));
                            }
                        }
                    }
                    //For Blast Email Groups....
                    foreach (EmailGroups beg in emailInfo.blastEmailGroups)
                    {
                        if (beg.IsSelected)
                        {
                            //This group is selected so let us get Email Addresses and add them as BCC
                            switch (beg.name)
                            {
                                case "All Coach":
                                    emailAdrsInfo = uow.EmailRepository().GetAllCoachAddresses().ToList();
                                    message = AddAddresses(emailAdrsInfo, message);
                                    break;
                                case "All Franchisee Owners":
                                    emailAdrsInfo = null;
                                    emailAdrsInfo = uow.EmailRepository().GetAllFranchiseeAddresses("FranchiseeOwner").ToList();
                                    message = AddAddresses(emailAdrsInfo, message);
                                    break;
                                case "Franchisee Owner":
                                    emailAdrsInfo = null;
                                    emailAdrsInfo = uow.EmailRepository().GetFranchiseeAddresses("FranchiseeOwner", CurrentUser.FranchiseeID).ToList();
                                    message = AddAddresses(emailAdrsInfo, message);
                                    break;
                                case "All Franchisee Users":
                                    emailAdrsInfo = null;
                                    emailAdrsInfo = uow.EmailRepository().GetAllFranchiseeAddresses("FranchiseeUser").ToList();
                                    message = AddAddresses(emailAdrsInfo, message);
                                    break;
                                case "Franchisee Users":
                                    emailAdrsInfo = null;
                                    emailAdrsInfo = uow.EmailRepository().GetFranchiseeAddresses("FranchiseeUser", CurrentUser.FranchiseeID).ToList();
                                    message = AddAddresses(emailAdrsInfo, message);
                                    break;
                                case "All Franchisee Contacts":
                                case "Franchisee Contacts":
                                    int FrId;
                                    emailAdrsInfo = null;
                                    if ((CurrentUser.Role == SandlerRoles.Corporate) || (CurrentUser.Role == SandlerRoles.SiteAdmin))
                                    {
                                        FrId = 0;
                                    }
                                    else
                                    {
                                        FrId = CurrentUser.FranchiseeID;
                                    }
                                    emailAdrsInfo = uow.EmailRepository().GetAllContactsAddresses(FrId).ToList();
                                    message = AddAddresses(emailAdrsInfo, message);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    //For User Grooup if any selected .....
                    foreach (EmailGroups usrg in emailInfo.userEmailGroups)
                    {
                        if (usrg.IsSelected)
                        {
                            emailAdrsInfo = null;
                            emailAdrsInfo = uow.EmailRepository().GetUserEmailGroupAddresses(Convert.ToInt32(usrg.Id)).ToList();
                            message = AddAddresses(emailAdrsInfo, message);
                        }
                    }
                    //For Attachement...
                    if (!string.IsNullOrEmpty(emailInfo.FILENAMES))
                    {
                        //Now save the file in the tmp folder
                        _file_path = System.Web.Hosting.HostingEnvironment.MapPath("~");
                        if (_file_path.Substring(_file_path.Length) != "\\")
                        {
                            _file_path += "\\";
                        }
                        _file_path += "Uploads\\" + emailInfo.FILENAMES;

                        using (System.IO.FileStream fileStream = new System.IO.FileStream(_file_path, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            System.Net.Mail.Attachment _attachment = new System.Net.Mail.Attachment(fileStream, emailInfo.FILENAME, MediaTypeNames.Application.Octet);
                            // Add time stamp information for the file.
                            ContentDisposition disposition = _attachment.ContentDisposition;
                            disposition.CreationDate = System.IO.File.GetCreationTime(_file_path);
                            disposition.ModificationDate = System.IO.File.GetLastWriteTime(_file_path);
                            disposition.ReadDate = System.IO.File.GetLastAccessTime(_file_path);
                            // Add the file attachment to this e-mail message.
                            message.Attachments.Add(_attachment);

                            //Send the message with Attachment
                            if (sendEmails)
                            {
                                client.Timeout = 30000000;
                                client.Send(message);
                                IsMessageSent = true;
                            }
                        }
                        //Now delete attachment
                        File.Delete(_file_path);
                    }
                    //Send the message for non-Attachment Messages...
                    if (sendEmails && !IsMessageSent)
                    {
                        client.Timeout = 30000000;
                        client.Send(message);
                    }
                    _response = new genericResponse() { success = true };
                    #endregion
                }
                else
                {
                    _response = new genericResponse() { success = false, message = "Recipient is missing. Either enter email address or select group from the list to proceed." };
                }
                #endregion
                //Back
                return _response;
            }
            catch (Exception ex)
            {
                _response = new genericResponse() { success = false, message = "There is a problem in sending the Email message. Please try again later. " + ex.Message };
                return _response;
            }
        }
        public genericResponse Save(CreateEmailGroupInfo createGrpInfo)
        {
            genericResponse _response;
            try
            {
                #region [[ Basic Check Here...]]

                if (createGrpInfo != null
                    && !string.IsNullOrEmpty(createGrpInfo.GRPNAME)
                    //Receipient(s) Selections...
                    && (CheckRecipientsExist(createGrpInfo.frcontactEmails)
                    || CheckRecipientsExist(createGrpInfo.frownerEmails)
                    || CheckRecipientsExist(createGrpInfo.fruserEmails)
                    || CheckRecipientsExist(createGrpInfo.frcoachEmails)))
                {
                    //Now we are good so go ahead and save this Group details....
                    _coachIds = GetSelectedList(createGrpInfo.frcoachEmails);
                    _frOwnerIds = GetSelectedList(createGrpInfo.frownerEmails);
                    _frUsersIds = GetSelectedList(createGrpInfo.fruserEmails);
                    _frContactsIds = GetSelectedListSpl(createGrpInfo.frcontactEmails);
                    //Now go ahead and add the group...
                    if (uow.EmailRepository().AddEmailUserGroup(createGrpInfo.GRPNAME, _coachIds, _frOwnerIds, _frUsersIds, _frContactsIds, CurrentUser.UserId.ToString()))
                    {
                        _response = new genericResponse() { success = true };
                    }
                    else
                    {
                        _response = new genericResponse() { success = false, message = "There is a problem in sending the Email message. Please try again later." };
                    }
                }
                else
                {
                    _response = new genericResponse() { success = false, message = "Please select at least one group to be included as Recipient(s) in this Email group to continue." };
                }
                #endregion
                //Go Back...
                return _response;
            }
            catch (Exception ex)
            {
                _response = new genericResponse() { success = false, message = "There is a problem in sending the Email message. Please try again later." };
                return _response;
            }
        }