Example #1
0
        public IActionResult GeneralNotice(GeneralNotice generalNotice)
        {
            var authorizedUser = new AppUser();

            if (HttpContext.Session.GetString("FrscQuestionLoggedInUser") != null)
            {
                var userString = HttpContext.Session.GetString("FrscQuestionLoggedInUser");
                authorizedUser = JsonConvert.DeserializeObject <AppUser>(userString);
            }

            if (!authorizedUser.Role.AccessAdminConsole || !authorizedUser.Role.ManageApplicationUser)
            {
                return(RedirectToAction("UnauthorizedAccess", "Home"));
            }

            var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("FrscQuestionLoggedInUserId"));
            var users          = _databaseConnection.AppUsers.ToList();

            generalNotice.DateCreated      = DateTime.Now;
            generalNotice.DateLastModified = DateTime.Now;
            generalNotice.CreatedBy        = signedInUserId;
            generalNotice.CreatedBy        = signedInUserId;

            _databaseConnection.GeneralNotices.Add(generalNotice);
            _databaseConnection.SaveChanges();

            new Mailer().SendGeneralNoticeEmail(new AppConfig().GeneralNoticeHtml, generalNotice, users);
            TempData["display"]          = "You have successfully sent a General Notice!";
            TempData["notificationtype"] = NotificationType.Success.ToString();
            return(RedirectToAction("GeneralNotice", "Page"));
        }
        //[AdminAuthorization]
        public IHttpActionResult PostGeneralNotice(GeneralNotice g)
        {
            grepo.Insert(g);
            string url = Url.Link("GetGeneralNoticeById", new { id = g.noticeid });

            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "GET", Relation = "Get General notice"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/", HttpMethod = "POST", Relation = "Self"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "PUT", Relation = "Edit general notice"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "Delete", Relation = "Delete General Notice"
            });


            return(Created(url, g));
        }
        //[AdminAuthorization]
        public IHttpActionResult PutGeneralNotice([FromBody] GeneralNotice g, [FromUri] int id)
        {
            g.noticeid = id;
            grepo.Edit(g);

            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "GET", Relation = "Get geenral Notice"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/", HttpMethod = "POST", Relation = "Create General Notice"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "PUT", Relation = "Self"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "Delete", Relation = "Delete General Notice"
            });


            return(Ok(g));
        }
        //[AdminAuthorization]
        public IHttpActionResult GetGeneralNotice(int id)
        {
            GeneralNotice g = grepo.GetByID(id);

            if (g == null)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }

            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "GET", Relation = "Self"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/", HttpMethod = "POST", Relation = "Create General Notice"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "PUT", Relation = "Edit general notice"
            });
            g.HyperLinks.Add(new HyperLink()
            {
                HRef = "http://localhost:44347/api/admins/gnotices/" + g.noticeid, HttpMethod = "Delete", Relation = "Delete General Notice"
            });


            return(Ok(g));
        }
Example #5
0
        public void SendGeneralNoticeEmail(string path, GeneralNotice generalNotice, List <AppUser> appUsers)
        {
            try
            {
                var client = new SmtpClient();
                //Smtp Server
                var smtpServer = new AppConfig().EmailServer;
                //Smtp Port Number
                var smtpPortNumber = new AppConfig().Port;

                client.Connect(smtpServer, smtpPortNumber);
                // Note: only needed if the SMTP server requires authentication
                // Error 5.5.1 Authentication
                client.Authenticate(new AppConfig().SupportEmail, new AppConfig().SupportEmailPassword);
                foreach (var item in appUsers)
                {
                    //From Address
                    var fromAddress     = "*****@*****.**";
                    var fromAdressTitle = "Afriplugz";
                    //To Address
                    var toVendor = item.Email;
                    //var toCustomer = email;
                    var toAdressTitle = item.Email;
                    var subject       = generalNotice.Subject;
                    //var BodyContent = message;

                    var mimeMessageVendor = new MimeMessage();
                    mimeMessageVendor.From.Add(new MailboxAddress(fromAdressTitle, fromAddress));
                    var check = false;
                    try
                    {
                        mimeMessageVendor.To.Add(new MailboxAddress(toAdressTitle, toVendor));
                    }
                    catch (Exception)
                    {
                        check = true;
                    }

                    if (check == false)
                    {
                        mimeMessageVendor.Subject  = subject;
                        mimeMessageVendor.Priority = MessagePriority.Urgent;
                        var bodyBuilder = new BodyBuilder();
                        using (var data = File.OpenText(path))
                        {
                            {
                                //manage content

                                bodyBuilder.HtmlBody = data.ReadToEnd();
                                var body = bodyBuilder.HtmlBody;

                                var replace = body.Replace("CONTENTBODY", generalNotice.Body);
                                replace = replace.Replace("USER", item.Name);
                                replace = replace.Replace("LOGO", new AppConfig().AppLogo);
                                replace = replace.Replace("APPURL", new AppConfig().AppUrl);
                                replace = replace.Replace("TC", new AppConfig().Terms);
                                replace = replace.Replace("PRIVACY", new AppConfig().PrivacyPolicy);
                                bodyBuilder.HtmlBody   = replace;
                                mimeMessageVendor.Body = bodyBuilder.ToMessageBody();
                            }
                        }

                        client.Send(mimeMessageVendor);
                    }
                }

                client.Disconnect(false);
            }
            catch (Exception)
            {
                // ignored
            }
        }