Beispiel #1
0
        string IEmail_Service.SendEmail(Email_Service_Model obj)
        {
            try
            {
                //Configuring webMail class to send emails
                //gmail smtp server
                WebMail.SmtpServer = "smtp.gmail.com";
                //gmail port to send emails
                WebMail.SmtpPort = 587;
                WebMail.SmtpUseDefaultCredentials = true;
                //sending emails with secure protocol
                WebMail.EnableSsl = true;
                //EmailId used to send emails from application
                WebMail.UserName = "******";
                WebMail.Password = "******";

                //Sender email address.
                WebMail.From = "*****@*****.**";

                //Send email
                WebMail.Send(to: obj.ToEmail, subject: obj.EmailSubject, body: obj.EMailBody, cc: obj.EmailCC, bcc: obj.EmailBCC, isBodyHtml: true);
                //ViewBag.Status = "Email Sent Successfully.";

                return("Email Sent Successfully.");
            }
            catch
            {
                return("Problem while sending email, Please check details.");
            }
        }
Beispiel #2
0
        public ActionResult MyPage(UserInfo info, FormCollection frm)
        {
            try
            {
                if (!string.IsNullOrEmpty(frm["Date"]))
                {
                    info.BirthDate = DateTime.Parse(frm["Date"]);
                }

                var result = _userProfile.PostEditUserProfile(info);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                Email_Service_Model email = new Email_Service_Model();
                email.ToEmail      = System.Configuration.ConfigurationManager.AppSettings["BccEmail"];
                email.EmailSubject = $"Failed to save my page data. {info.UserId}";
                email.EMailBody    = $"Name: {info.Name}. Id:{info.UserId}. Exception: {ex.ToString()}";

                var emailmanager = new UtilityManager();
                emailmanager.SendEmail(email);
            }

            return(View(_userProfile.EditUserProfile()));
        }
        public ActionResult Create(NoticeBoard model)
        {
            try
            {
                model.CreatorId = User.Identity.GetUserId();

                var notice = _noticeBoardManager.PostNotices(model);

                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Guid.NewGuid() + "_" + Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/Content/images/"), fileName);
                        file.SaveAs(path);
                        var image = new SiteImage
                        {
                            ImagePath  = "/Content/images/" + fileName,
                            Type       = "Notice",
                            TypeId     = notice.Id,
                            UploadDate = DateTime.Now,
                            UploaderId = notice.CreatorId
                        };
                        _noticeBoardManager.SaveImage(image);
                    }

                    else
                    {
                        var image = new SiteImage
                        {
                            ImagePath  = "/Content/images/Event/defaultNotice.png",
                            Type       = "Notice",
                            TypeId     = notice.Id,
                            UploadDate = DateTime.Now,
                            UploaderId = notice.CreatorId
                        };
                        _noticeBoardManager.SaveImage(image);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error($"Error creating notice. {ex}");
                Email_Service_Model email = new Email_Service_Model();
                email.ToEmail      = System.Configuration.ConfigurationManager.AppSettings["BccEmail"];
                email.EmailSubject = $"Failed to create notice. User- {model.Creator.UserName}";
                email.EMailBody    = $"Description: {model.Description}. Title: {model.Title}. Exception: {ex.ToString()}";

                var emailmanager = new UtilityManager();
                emailmanager.SendEmail(email);
            }



            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public EventModel Create(EventModel model, List <string> inviteesIds)
        {
            EventModel Data = new EventModel();

            try
            {
                Data.Title       = model.Title;
                Data.Description = !string.IsNullOrEmpty(model.Description)? model.Description.Replace(System.Environment.NewLine, "<br/>"):model.Description;
                Data.Date        = model.Date;
                Data.Place       = model.Place;

                Data.Creation  = DateTime.Now;
                Data.CreatorId = Current_User_id;

                Data.EventStatus  = true;
                Data.IsApproved   = true;
                Data.End          = model.End;
                Data.ApprovalDate = DateTime.Now;
                Data.IsPublic     = inviteesIds.Any() ? false : true;



                _data.Event.Add(Data);
                _data.SaveChanges();
                Data.UniqueUrl = $"{Data.EventId}-{Data.Title.Replace(" ", "-")}";
                _data.SaveChanges();
                if (Data.IsPublic == false)
                {
                    CreateMember(Data, inviteesIds);
                }



                return(Data);
            }

            catch (Exception ex)
            {
                Email_Service_Model email = new Email_Service_Model();
                email.ToEmail      = System.Configuration.ConfigurationManager.AppSettings["BccEmail"];
                email.EmailSubject = "Failed to create notice.";
                email.EMailBody    = $"Description: {model.Description}. Title: {model.Title}. Exception: {ex.ToString()}";

                var emailmanager = new UtilityManager();
                emailmanager.SendEmail(email);
                return(Data);
            }
        }
        public ActionResult SendEmail(Email_Service_Model obj)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string Result = Email.SendEmail(obj);

                    TempData["Message"] = Result;
                }
                catch (Exception)
                {
                    TempData["Message"] = "Problem while sending email, Please check details.";
                }
            }
            return(RedirectToAction("SendEmail"));
        }
Beispiel #6
0
        public async Task <ActionResult> Register(InternalRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                //TODO: have to fix for password.
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    //For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    //Send an email with this link

                    //string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    //await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    // Note : _UserAccountProfile doesnt work as it has a constructor parameter
                    //_UserAccountProfile.AddationalInfo(model);
                    //_UserAccountProfile.SetUserRole(model.Email);

                    _UserProfile.AddationalInfo(model);
                    _UserProfile.SetUserRole(model.Email);

                    Email_Service_Model email = new Email_Service_Model();
                    email.ToEmail      = System.Configuration.ConfigurationManager.AppSettings["BccEmail"];
                    email.EmailSubject = $"{model.Name} signed up.";
                    email.EMailBody    = $"Name: {model.Name}. Email:{model.Email}";

                    var emailmanager = new UtilityManager();
                    emailmanager.SendEmail(email);

                    return(RedirectToAction("New_Registration", new { Id = user.Id }));
                }
                logger.Error($"Error signing up. {model.Email}");
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #7
0
        public string SendEmail(Email_Service_Model obj)
        {
            try
            {
                //Configuring webMail class to send emails
                //gmail smtp server

                //WebMail.SmtpServer = "smtp.gmail.com";
                WebMail.SmtpServer = Helpers.Constants.SmtpServer;

                //gmail port to send emails

                //WebMail.SmtpPort = 587;
                WebMail.SmtpPort = Int32.Parse(Helpers.Constants.SmtpPort);


                WebMail.SmtpUseDefaultCredentials = true;
                //sending emails with secure protocol
                WebMail.EnableSsl = true;
                //EmailId used to send emails from application

                //WebMail.UserName = "******";
                WebMail.UserName = System.Configuration.ConfigurationManager.AppSettings["UserName"];


                //WebMail.Password = "******";
                WebMail.Password = System.Configuration.ConfigurationManager.AppSettings["Password"];

                //Sender email address.
                //WebMail.From = "*****@*****.**";
                WebMail.From = System.Configuration.ConfigurationManager.AppSettings["From"];

                //Send email
                WebMail.Send(to: obj.ToEmail, subject: obj.EmailSubject, body: obj.EMailBody, cc: obj.EmailCC, bcc: obj.EmailBCC, isBodyHtml: true);
                //ViewBag.Status = "Email Sent Successfully.";

                //return "Email Sent Successfully.";
                return(Helpers.Constants.Send);
            }
            catch
            {
                return(Helpers.Constants.Fail);
            }
        }
Beispiel #8
0
        public string Create(JobApplication myform)
        {
            try
            {
                Job_Application apply = new Job_Application();

                System.Random rand   = new System.Random((int)System.DateTime.Now.Ticks);
                int           random = rand.Next(1, 100000000);

                apply.Application_id = random.ToString();   // Auto generate hobe

                apply.First_name = myform.First_name;
                apply.Last_name  = myform.Last_name;
                apply.Address    = myform.Address;
                apply.Phone      = myform.Phone;
                apply.Email      = myform.Email;
                apply.Gender     = myform.Gender;

                apply.DateOfBirth = myform.Date + "-" + myform.Month + "-" + myform.BirthYear;

                apply.Marrage_status = myform.Marrage_status;
                apply.Last_degree    = myform.Last_degree;
                apply.Year           = myform.Year;
                apply.Subject        = myform.Subject;
                apply.Post           = myform.Post;
                apply.About          = myform.About;

                Data.Job_Application.Add(apply);

                Data.SaveChanges();

                //ModelState.Clear();



                try
                {
                    System.Random rand1   = new System.Random((int)System.DateTime.Now.Ticks);
                    int           random1 = rand1.Next(1, 100000000);

                    string       Path = @"D:\Repositories\HatBazar\Email_Document\Job_Application\" + random1 + ".txt";
                    StreamWriter sw   = new StreamWriter(Path);

                    //Write a line of text

                    sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Job_Application\Document1.txt"));

                    sw.WriteLine("Application ID :" + apply.Application_id);
                    sw.WriteLine("First Name :" + apply.First_name);
                    sw.WriteLine("Last Name :" + apply.Last_name);
                    sw.WriteLine("Address :" + apply.Address);
                    sw.WriteLine("Phone Number :" + apply.Phone);
                    sw.WriteLine("Email :" + apply.Email);
                    sw.WriteLine("Gender :" + apply.Gender);
                    sw.WriteLine("Date of Birth :" + apply.DateOfBirth);
                    sw.WriteLine("Maritarial Status :" + apply.Marrage_status);
                    sw.WriteLine("Latest Degree :" + apply.Last_degree);
                    sw.WriteLine("Year of Passing :" + apply.Year);
                    sw.WriteLine("Subject :" + apply.Subject);
                    sw.WriteLine("Post :" + apply.Post);
                    sw.WriteLine("Resume  :" + apply.About);
                    //sw.WriteLine("all Togather :" + apply);

                    sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Job_Application\Document2.txt"));
                    sw.Close();
                    try
                    {
                        //Email_ServiceController Email = new Email_ServiceController();
                        IEmail_Service      Email = new Email_ServiceClass();
                        Email_Service_Model obj   = new Email_Service_Model();

                        obj.ToEmail      = apply.Email;
                        obj.EmailSubject = "Hat Bazar";
                        obj.EMailBody    = System.IO.File.ReadAllText(Path);

                        return(Email.SendEmail(obj));
                    }
                    catch (Exception)
                    {
                        return("Problem while sending email, Please check details.");
                    }
                }

                catch
                {
                    return("Path Missing .");
                }
            }
            catch
            {
                return("Path Missing to save Email.");
            }
        }
Beispiel #9
0
        public string Submit(string Customer_id, string UserName)
        {
            try
            {
                List <Customer_Order> submitionList = Data.Customer_Order.Where(x => x.Purches_id == Customer_id && x.Order_Status == 1).ToList();
                int           Total  = 0;
                System.Random rand   = new System.Random((int)System.DateTime.Now.Ticks);
                int           random = rand.Next(1, 100000000);

                string Path = @"D:\Repositories\HatBazar\Email_Document\Customer_Order\" + random + ".txt";
                //Pass the filepath and filename to the StreamWriter Constructor

                //StreamWriter sw = new StreamWriter(@"D:\Repositories\HatBazar\Email_Document\Admin_Email\Document.txt");
                StreamWriter sw = new StreamWriter(Path);

                //Write a line of text

                sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Customer_Order\Order1.txt"));
                sw.WriteLine("Date :" + DateTime.Now);
                //***************************************************

                foreach (var i in submitionList)
                {
                    if (i.Unit_name == "PACKAGE")
                    {
                        int packageid = (i.Product_id).Value;
                        List <Package_With_Product> Item = Data.Package_With_Product.Where(x => x.Package_Id == packageid).ToList();
                        foreach (var product in Item)
                        {
                            Product_Stock CO = Data.Product_Stock.Single(Z => Z.Product_id == product.Product_Id);

                            int J = Int32.Parse(CO.Stock_unit);
                            J                    = J - product.Unit_Number;
                            CO.Stock_unit        = J.ToString();
                            Data.Entry(CO).State = EntityState.Modified;

                            bool Check = Data.Order_For_Shop.Any(x => x.Product_Name == (product.Product_Name));
                            if (Check == true)
                            {
                                Order_For_Shop order = Data.Order_For_Shop.Single(Z => Z.Product_Name == product.Product_Name);

                                order.Unit_Number = product.Unit_Number + (order.Unit_Number);

                                var price = Data.Product_Information.Single(x => x.Product_id == order.Product_Id);
                                order.Total_Price       = (order.Unit_Number) * (price.Price_per_unit);
                                Data.Entry(order).State = EntityState.Modified;
                                Product_SellingDate psd = new Product_SellingDate();
                                psd.Product_Id   = order.Product_Id;
                                psd.Product_Name = order.Product_Name;
                                psd.Unit_Number  = product.Unit_Number;
                                psd.Unit_Name    = order.Unit_Name;
                                psd.Price        = i.Price * product.Unit_Number;
                                psd.Selected     = 0;
                                var dateTimeNow = DateTime.Now; // Return 00/00/0000 00:00:00
                                psd.Date = dateTimeNow.ToShortDateString();

                                Data.Product_SellingDate.Add(psd);
                                Data.SaveChanges();
                            }
                            else
                            {
                                Order_For_Shop OF = new Order_For_Shop();
                                OF.Product_Name = product.Product_Name;
                                OF.Unit_Name    = product.Unit_Name;
                                OF.Unit_Number  = product.Unit_Number;
                                var price = Data.Product_Information.Single(x => x.Product_id == OF.Product_Id);
                                OF.Total_Price = price.Price_per_unit;
                                Data.Order_For_Shop.Add(OF);

                                Product_SellingDate psd = new Product_SellingDate();
                                psd.Product_Id   = OF.Product_Id;
                                psd.Product_Name = product.Product_Name;
                                psd.Unit_Number  = product.Unit_Number;
                                psd.Unit_Name    = product.Unit_Name;
                                psd.Price        = i.Price * product.Unit_Number;
                                psd.Selected     = 0;
                                var dateTimeNow = DateTime.Now; // Return 00/00/0000 00:00:00
                                psd.Date = dateTimeNow.ToShortDateString();

                                Data.Product_SellingDate.Add(psd);
                                Data.SaveChanges();
                            }
                        }
                    }
                    else
                    {
                        Product_Stock CO = Data.Product_Stock.Single(Z => Z.Product_id == (i.Product_id).Value);

                        int J = Int32.Parse(CO.Stock_unit);
                        J                    = J - (i.Unit_number).Value;
                        CO.Stock_unit        = J.ToString();
                        Data.Entry(CO).State = EntityState.Modified;

                        bool Check = Data.Order_For_Shop.Any(x => x.Product_Name == (i.Product_Name));
                        if (Check == true)
                        {
                            Order_For_Shop order = Data.Order_For_Shop.Single(Z => Z.Product_Name == i.Product_Name);

                            order.Unit_Number = (i.Unit_number).Value + (order.Unit_Number);
                            var price = Data.Product_Information.Single(x => x.Product_name == order.Product_Name);
                            //  var price = Data.Product_Information.Single(x => x.Product_id == order.Product_Id);
                            order.Total_Price       = (order.Unit_Number) * (price.Price_per_unit);
                            Data.Entry(order).State = EntityState.Modified;

                            Product_SellingDate psd = new Product_SellingDate();
                            psd.Product_Id   = order.Product_Id;
                            psd.Product_Id   = order.Product_Id;
                            psd.Product_Name = order.Product_Name;
                            psd.Unit_Number  = i.Unit_number;
                            psd.Unit_Name    = order.Unit_Name;
                            psd.Price        = price.Price_per_unit * i.Unit_number;
                            psd.Selected     = 0;
                            var dateTimeNow = DateTime.Now; // Return 00/00/0000 00:00:00
                            psd.Date = dateTimeNow.ToShortDateString();

                            Data.Product_SellingDate.Add(psd);
                            Data.SaveChanges();
                        }
                        else
                        {
                            Order_For_Shop OF = new Order_For_Shop();
                            //OF.Product_Id = (i.Product_id).Value;
                            OF.Product_Name = i.Product_Name;
                            OF.Unit_Name    = i.Unit_name;
                            OF.Unit_Number  = (i.Unit_number).Value;
                            Data.Order_For_Shop.Add(OF);

                            Product_SellingDate psd = new Product_SellingDate();
                            psd.Product_Id = (i.Product_id).Value;


                            psd.Product_Name = i.Product_Name;
                            psd.Unit_Number  = i.Unit_number;
                            psd.Unit_Name    = i.Unit_name;
                            psd.Price        = i.Price * i.Unit_number;
                            psd.Selected     = 0;
                            var dateTimeNow = DateTime.Now; // Return 00/00/0000 00:00:00
                            psd.Date = dateTimeNow.ToShortDateString();

                            Data.Product_SellingDate.Add(psd);
                            Data.SaveChanges();
                        }
                    }
                    i.Order_Status = 0;
                    var date = DateTime.Now;
                    i.Date = date.ToShortDateString();
                    Data.Entry(i).State = EntityState.Modified;



                    //***********************************

                    try
                    {
                        string Information = "Product Name :" + i.Product_Name + "Unit :" + i.Unit_number + "" + i.Unit_name + "Price:" + (i.Unit_number * i.Price);
                        sw.WriteLine(Information);
                        Total = Total + (i.Unit_number * i.Price).Value;
                    }

                    catch
                    {
                        return("Path Missing to save Email.");
                    }

                    //***********************************
                }
                Order_with_Date OD = new Order_with_Date();

                var date2 = DateTime.Now;
                OD.Date = date2.ToShortDateString();

                OD.User_Name   = UserName;
                OD.Total_Price = Total;
                Data.Order_with_Date.Add(OD);
                Data.SaveChanges();

                sw.WriteLine("Total : " + Total);
                sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Customer_Order\Order2.txt"));
                sw.Close();



                IEmail_Service       email = new Email_ServiceClass();
                int                  ia    = Int32.Parse(Customer_id);
                Customer_Information Info  = Data.Customer_Information.Single(x => x.Customer_id == ia);
                Email_Service_Model  obj   = new Email_Service_Model();

                obj.ToEmail      = Info.Email;
                obj.EmailSubject = "Hat Bazar";
                obj.EMailBody    = System.IO.File.ReadAllText(Path);

                return(email.SendEmail(obj));
            }

            catch
            {
                return("Submission Failure");
            }
        }
Beispiel #10
0
        public string Complain(Complain complain)
        {
            Customer_Complain CC = new Customer_Complain();

            try
            {
                Customer_Information C = Data.Customer_Information.First(x => x.User_id == complain.User_Name);

                CC.Customer_ID = C.Customer_id;
                CC.DateTime    = DateTime.Now;
                CC.Massage     = complain.Message;

                Data.Customer_Complain.Add(CC);

                Data.SaveChanges();

                //ModelState.Clear();
                //TempData["Message"] = "Complain Submitted.";



                try
                {
                    System.Random rand   = new System.Random((int)System.DateTime.Now.Ticks);
                    int           random = rand.Next(1, 100000000);

                    string Path = @"D:\Repositories\HatBazar\Email_Document\Admin_Email\" + random + ".txt";
                    //Pass the filepath and filename to the StreamWriter Constructor

                    //StreamWriter sw = new StreamWriter(@"D:\Repositories\HatBazar\Email_Document\Admin_Email\Document.txt");
                    StreamWriter sw = new StreamWriter(Path);

                    //Write a line of text

                    sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Admin_Email\Admin1.txt"));
                    sw.WriteLine(complain.Message);


                    sw.WriteLine(System.IO.File.ReadAllText(@"D:\Repositories\HatBazar\Email_Document\Admin_Email\Admin2.txt"));
                    //Write a second line of text
                    //sw.WriteLine("From the StreamWriter class");

                    //Close the file
                    sw.Close();



                    try
                    {
                        //Email_ServiceController Email = new Email_ServiceController();
                        IEmail_Service      Email = new Email_ServiceClass();
                        Email_Service_Model obj   = new Email_Service_Model();

                        obj.ToEmail      = C.Email;
                        obj.EmailSubject = "Hat Bazar";
                        obj.EMailBody    = System.IO.File.ReadAllText(Path);

                        return(Email.SendEmail(obj));
                    }
                    catch (Exception)
                    {
                        return("Problem while sending email, Please check details.");
                    }
                }

                catch
                {
                    return("Path Missing to save Email.");
                }
            }

            catch
            {
                //ModelState.Clear();
                return("Invalid User Name.");
            }
        }
Beispiel #11
0
        public bool CreateSurvey(PollViewModel model, string[] Questions)
        {
            try
            {
                Array.Reverse(Questions);

                var start = model.StartDate.Date.ToString();
                var end   = model.EndDate.Date.ToString();

                PollingAndSyrvayModel Data = new PollingAndSyrvayModel
                {
                    Name        = "Survey",
                    Title       = model.Title,
                    Description = model.Description,
                    StartDate   = DateTime.ParseExact(start, "dd-MM-yyyy hh:mm:ss", CultureInfo.InvariantCulture), // String to datetime
                    EndDate     = DateTime.ParseExact(end, "dd-MM-yyyy hh:mm:ss", CultureInfo.InvariantCulture),   // String to datetime
                    Creation    = DateTime.Now.Date,
                    CreatorId   = Current_User_id,

                    Status       = true,
                    IsApproved   = true,
                    ApprovalDate = DateTime.Now.Date,
                    IsPublic     = true,
                };


                _data.PollingAndSyrvays.Add(Data);
                _data.SaveChanges();

                List <QuestionModel> QuestionList = new List <QuestionModel>();
                foreach (var i in Questions)
                {
                    if (i != "")
                    {
                        if (Char.IsDigit(i[0]) && i[i.Length - 1] == '?')
                        {
                            QuestionModel qus = new QuestionModel
                            {
                                ActivityName = "Survey",
                                ActivityId   = Data.Id,
                                Question     = i.Remove(i.Length - 1),
                            };

                            QuestionList.Add(qus);
                        }
                    }
                }



                _data.Questions.AddRange(QuestionList);
                _data.SaveChanges();


                List <AnswerModel> AnswerList = new List <AnswerModel>();
                int j = 0;
                foreach (var z in QuestionList)
                {
                    for (int i = j; i < Questions.Length;)
                    {
                        if (Questions[i] != "" && Questions[i].Remove(Questions[i].Length - 1) == z.Question)
                        {
                            i++;
                            if (Questions[i] != "")
                            {
                                var  x  = Questions[i][0];
                                bool x1 = Char.IsDigit(Questions[i][0]);

                                var  y1  = Questions[i][Questions[i].Length - 1];
                                bool y11 = Questions[i][Questions[i].Length - 1] == '?';


                                while ((Questions[i] != "") && ((!Char.IsDigit(Questions[i][0])) || !(Questions[i][Questions[i].Length - 1] == '?')))
                                {
                                    AnswerModel answer = new AnswerModel
                                    {
                                        QuestionId = z.Id,
                                        Answer     = Questions[i]
                                    };
                                    AnswerList.Add(answer);
                                    i++;
                                    if (i >= Questions.Length)
                                    {
                                        break;
                                    }
                                }
                                j = i;
                                break;
                            }
                            else
                            {
                                i++;
                                if (i >= Questions.Length)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            i++;
                            if (i >= Questions.Length)
                            {
                                break;
                            }
                        }
                    }
                }


                _data.Answers.AddRange(AnswerList);
                _data.SaveChanges();



                return(true);
            }

            catch (Exception ex)
            {
                Email_Service_Model email = new Email_Service_Model
                {
                    ToEmail      = System.Configuration.ConfigurationManager.AppSettings["BccEmail"],
                    EmailSubject = "Failed to create notice.",
                    EMailBody    = $"Description: {model.Description}. Title: {model.Title}. Exception: {ex.ToString()}"
                };

                var emailmanager = new UtilityManager();
                emailmanager.SendEmail(email);
                return(false);
            }
        }
Beispiel #12
0
        public bool CreatePoll(PollViewModel model, List <string> inviteesIds)
        {
            try
            {
                var start = model.StartDate.Date.ToString();
                var end   = model.EndDate.Date.ToString();

                PollingAndSyrvayModel Data = new PollingAndSyrvayModel
                {
                    Name        = "Poll",
                    Title       = model.Title,
                    Description = model.Description,
                    StartDate   = DateTime.ParseExact(start, "dd-MM-yyyy hh:mm:ss", CultureInfo.InvariantCulture), // String to datetime
                    EndDate     = DateTime.ParseExact(end, "dd-MM-yyyy hh:mm:ss", CultureInfo.InvariantCulture),   // String to datetime
                    Creation    = DateTime.Now.Date,
                    CreatorId   = Current_User_id,

                    Status       = true,
                    IsApproved   = true,
                    ApprovalDate = DateTime.Now.Date,
                    IsPublic     = inviteesIds.Any() ? false : true
                };


                _data.PollingAndSyrvays.Add(Data);
                _data.SaveChanges();


                QuestionModel qus = new QuestionModel
                {
                    ActivityName = "Poll",
                    ActivityId   = Data.Id,
                    Question     = model.Question
                };

                _data.Questions.Add(qus);
                _data.SaveChanges();


                List <AnswerModel> AnswerList = new List <AnswerModel>();
                AnswerModel        answer     = new AnswerModel
                {
                    QuestionId = qus.Id,
                    Answer     = "Yes"
                };


                AnswerList.Add(answer);

                AnswerModel answer2 = new AnswerModel
                {
                    QuestionId = qus.Id,
                    Answer     = "No"
                };

                AnswerList.Add(answer2);
                _data.Answers.AddRange(AnswerList);
                _data.SaveChanges();


                if (Data.IsPublic == false)
                {
                    model.Id = Data.Id;
                    Perticipents(model, inviteesIds);
                }

                return(true);
            }

            catch (Exception ex)
            {
                Email_Service_Model email = new Email_Service_Model
                {
                    ToEmail      = System.Configuration.ConfigurationManager.AppSettings["BccEmail"],
                    EmailSubject = "Failed to create notice.",
                    EMailBody    = $"Description: {model.Description}. Title: {model.Title}. Exception: {ex.ToString()}"
                };

                var emailmanager = new UtilityManager();
                emailmanager.SendEmail(email);
                return(false);
            }
        }