Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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);
            }
        }