Пример #1
0
        public string AddEntry()
        {
            string result = "";
            var    email  = GlobalData.GetEmail();

            if (email != null)
            {
                using (var context = new NCContext.NCContext())
                {
                    var student = context.Students.Where(x => x.Email == email).FirstOrDefault();
                    var num     = context.Surveys.Where(x => x.StudentId == student.Id).FirstOrDefault();
                    if (num == null)
                    {
                        Survey survey = new Survey();
                        survey.StudentId = student.Id;
                        context.Surveys.Add(survey);
                        context.SaveChanges();
                        int id = survey.Id;
                        survey.SurveyNo = id;
                        context.SaveChanges();
                        return("true");
                    }
                    else
                    {
                        return("You already take survey");
                    }
                }
            }
            return(result);
        }
Пример #2
0
        public string StatusChange(int Id, int status)
        {
            string result = "Internal Server Error";

            if (status > 0 && Id > 0)
            {
                try
                {
                    using (var context = new NCContext.NCContext())
                    {
                        var survey = context.Surveys.Where(x => x.Id == Id).FirstOrDefault();
                        if (survey != null)
                        {
                            survey.Status = status;
                            context.Entry(survey).State = EntityState.Modified;
                            context.SaveChanges();
                            var student = context.Students.Where(x => x.Id == survey.StudentId).FirstOrDefault();
                            var subject = "Event Subscribed";
                            var body    = "Hi, thank you for giving your time and playing the survey as a result you win the cofee card.";
                            SendEmail(student.Email, body, subject);
                            result = "true";
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }
            }
            return(result);
        }
Пример #3
0
 public ActionResult UnSubscribe(string Email, int EventId)
 {
     if (!string.IsNullOrEmpty(Email) && EventId > 0)
     {
         using (var context = new NCContext.NCContext())
         {
             var student = context.Students.Where(x => x.Email == Email).FirstOrDefault();
             if (student != null)
             {
                 var e_subscribed = context.EventsSubscribers.Where(x => x.EventId == EventId && x.StudentId == student.Id).FirstOrDefault();
                 if (e_subscribed != null)
                 {
                     context.EventsSubscribers.Remove(e_subscribed);
                     context.SaveChanges();
                     var evet    = context.Events.Where(x => x.Id == EventId).FirstOrDefault();
                     var subject = "Event UnSubscribed";
                     var body    = "Hi, you have UnSubscribed from Event: " + evet.Title;
                     SendEmail(Email, body, subject);
                     return(RedirectToAction("Events"));
                 }
             }
         }
     }
     return(RedirectToAction("Events"));
 }
Пример #4
0
        public string ChangeStatus(int Id, int status)
        {
            string result = "Internal Server Error";

            if (status > 0 && Id > 0)
            {
                try
                {
                    using (var context = new NCContext.NCContext())
                    {
                        var post = context.Posts.Where(x => x.Id == Id).FirstOrDefault();
                        if (post != null)
                        {
                            post.ApprovalStatus       = status;
                            post.Date                 = DateTime.Now;
                            context.Entry(post).State = EntityState.Modified;
                            context.SaveChanges();
                            result = "true";
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }
            }
            return(result);
        }
Пример #5
0
        public string ForgotPassword(string email)
        {
            string result = "";

            try
            {
                string resetCode = Guid.NewGuid().ToString();
                string verifyUrl = "/Account/ResetPassword/" + resetCode;
                var    link      = Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery, verifyUrl);
                using (var context = new NCContext.NCContext())
                {
                    var getuser = context.Students.Where(x => x.Email == email).FirstOrDefault();
                    if (getuser != null)
                    {
                        getuser.ResetPasswordCode = resetCode;
                        context.SaveChanges();
                        var subject = "Password Reset Request";
                        var body    = "Hi " + getuser.FName + ", You recently requested to reset your password for your account. Click the link to reset it. "

                                      + link + " If you did not request a password reset, please ignore this email. Thank you";
                        SendEmail(email, body, subject);
                        result = "true";
                    }
                    else
                    {
                        result = "Email is not valid";
                    }
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
Пример #6
0
 public string EditCategory(EventCategory eventCategory)
 {
     using (var context = new NCContext.NCContext())
     {
         context.Entry(eventCategory).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
         return("true");
     }
 }
Пример #7
0
        public string AddPromotion(Promotion promotion)
        {
            string result = "";

            using (var context = new NCContext.NCContext())
            {
                context.Promotions.Add(promotion);
                context.SaveChanges();
                result = "true";
            }
            return(result);
        }
Пример #8
0
        public string EditPromotion(Promotion promotion)
        {
            string result = "";

            using (var context = new NCContext.NCContext())
            {
                context.Entry(promotion).State = EntityState.Modified;
                context.SaveChanges();
                result = "true";
            }
            return(result);
        }
Пример #9
0
 public string EditPost(Post post)
 {
     if (post != null)
     {
         using (var context = new NCContext.NCContext())
         {
             context.Entry(post).State = EntityState.Modified;
             context.SaveChanges();
             return("true");
         }
     }
     return("Internal Server Error");
 }
Пример #10
0
 public string DeleteStudent(int Id)
 {
     using (var context = new NCContext.NCContext())
     {
         var student = context.Students.Where(x => x.Id == Id).FirstOrDefault();
         if (student != null)
         {
             context.Students.Remove(student);
             context.SaveChanges();
             return("true");
         }
     }
     return("Internal Server Error");
 }
Пример #11
0
        public string Feedback(Feedback feedback)
        {
            string result = "";

            if (feedback != null)
            {
                using (var context = new NCContext.NCContext())
                {
                    context.Feedbacks.Add(feedback);
                    context.SaveChanges();
                    result = "true";
                }
            }
            return(result);
        }
Пример #12
0
 public string AddEvent(Event evnt)
 {
     using (var context = new NCContext.NCContext())
     {
         if (evnt != null)
         {
             context.Events.Add(evnt);
             context.SaveChanges();
             return("true");
         }
         else
         {
             return("All Fields are Required");
         }
     }
 }
Пример #13
0
 public string EditEvent(Event evnt)
 {
     if (evnt != null)
     {
         using (var context = new NCContext.NCContext())
         {
             context.Entry(evnt).State = System.Data.Entity.EntityState.Modified;
             context.SaveChanges();
             return("true");
         }
     }
     else
     {
         return("Internal Server Error");
     }
 }
Пример #14
0
 public string AddCategory(EventCategory eventCategory)
 {
     using (var context = new NCContext.NCContext())
     {
         if (eventCategory != null)
         {
             context.EventCategories.Add(eventCategory);
             context.SaveChanges();
             return("true");
         }
         else
         {
             return("Name Field is Required");
         }
     }
 }
Пример #15
0
        public string DeletePromotion(int Id)
        {
            string result = "";

            using (var context = new NCContext.NCContext())
            {
                var promotion = context.Promotions.Where(x => x.Id == Id).FirstOrDefault();
                if (promotion != null)
                {
                    context.Promotions.Remove(promotion);
                    context.SaveChanges();
                    result = "true";
                }
            }
            return(result);
        }
Пример #16
0
        public string DeleteFeedback(int Id)
        {
            string result = "";

            using (var context = new NCContext.NCContext())
            {
                var feedback = context.Feedbacks.Where(x => x.Id == Id).FirstOrDefault();
                if (feedback != null)
                {
                    context.Feedbacks.Remove(feedback);
                    context.SaveChanges();
                    result = "true";
                }
            }
            return(result);
        }
Пример #17
0
 public string ResetPassword(GetResetPasswordViewModel model)
 {
     if (!string.IsNullOrEmpty(model.NewPassword))
     {
         using (var context = new NCContext.NCContext())
         {
             var user = context.Students.Where(a => a.ResetPasswordCode == model.Resetpasswordcode).FirstOrDefault();
             if (user != null)
             {
                 var u = context.Users.Where(x => x.Email == user.Email).FirstOrDefault();
                 u.Password             = model.NewPassword;
                 user.Password          = model.NewPassword;
                 user.ResetPasswordCode = "";
                 context.SaveChanges();
                 return("true");
             }
         }
         return("Something wrong happned");
     }
     return("Something wrong happned");
 }
Пример #18
0
 public ActionResult Signup(Student student)
 {
     using (var context = new NCContext.NCContext())
     {
         if (student != null)
         {
             if (!string.IsNullOrEmpty(student.Email) && !string.IsNullOrEmpty(student.Password) && !string.IsNullOrEmpty(student.FName) && !string.IsNullOrEmpty(student.LName))
             {
                 var isuser = context.Users.Where(x => x.Email == student.Email).FirstOrDefault();
                 if (isuser == null)
                 {
                     User user = new User();
                     user.Email    = student.Email;
                     user.Role     = "student";
                     user.Password = student.Password;
                     context.Students.Add(student);
                     context.Users.Add(user);
                     context.SaveChanges();
                     FormsAuthentication.SetAuthCookie(student.Email.ToLower(), true);
                     return(RedirectToAction("Login", "Account"));
                 }
                 else
                 {
                     ViewBag.error = "exist";
                     return(View());
                 }
             }
             else
             {
                 return(View());
             }
         }
         else
         {
             return(View());
         }
     }
 }
Пример #19
0
 public string AddPost(Post post)
 {
     if (post != null)
     {
         using (var context = new NCContext.NCContext())
         {
             var email = GlobalData.GetEmail();
             if (!string.IsNullOrEmpty(email))
             {
                 var student = context.Students.Where(x => x.Email == email).FirstOrDefault();
                 if (student != null)
                 {
                     post.Date      = DateTime.Now;
                     post.StudentId = student.Id;
                     context.Posts.Add(post);
                     context.SaveChanges();
                     return("true");
                 }
             }
         }
     }
     return("Server Error");
 }
Пример #20
0
 public string DeleteCategory(int Id)
 {
     if (Id > 0)
     {
         using (var context = new NCContext.NCContext())
         {
             var category = context.EventCategories.Where(x => x.Id == Id).FirstOrDefault();
             if (category != null)
             {
                 context.EventCategories.Remove(category);
                 context.SaveChanges();
                 return("true");
             }
             else
             {
                 return("Internal Server Error");
             }
         }
     }
     else
     {
         return("Internal Server Error");
     }
 }
Пример #21
0
 public ActionResult Subscribe(string Email, int EventId)
 {
     if (!(string.IsNullOrEmpty(Email)) && EventId > 0)
     {
         EventsSubscribers eventsSubscribers = new EventsSubscribers();
         using (var context = new NCContext.NCContext())
         {
             var student = context.Students.Where(x => x.Email == Email).FirstOrDefault();
             if (student != null)
             {
                 eventsSubscribers.StudentId = student.Id;
                 eventsSubscribers.EventId   = EventId;
                 context.EventsSubscribers.Add(eventsSubscribers);
                 context.SaveChanges();
                 var evet    = context.Events.Where(x => x.Id == EventId).FirstOrDefault();
                 var subject = "Event Subscribed";
                 var body    = "Hi, you have Successfuly subscribed the Event " + evet.Title;
                 SendEmail(Email, body, subject);
                 return(RedirectToAction("Events"));
             }
         }
     }
     return(RedirectToAction("Events"));
 }
Пример #22
0
 public string DeleteEvent(int Id)
 {
     if (Id > 0)
     {
         using (var context = new NCContext.NCContext())
         {
             var evnt = context.Events.Where(x => x.Id == Id).FirstOrDefault();
             if (evnt != null)
             {
                 context.Events.Remove(evnt);
                 context.SaveChanges();
                 return("true");
             }
             else
             {
                 return("Internal Server Error");
             }
         }
     }
     else
     {
         return("Internal Server Error");
     }
 }