Exemplo n.º 1
0
        public ActionResult Create(Group model)
        {
            ApplicationDbContext context = new ApplicationDbContext();

            try
            {
                if (ModelState.IsValid)
                {
                    string dateTimeFailureMessage = Functions.CheckDatesForGroup(model.StartDate, model.EndDate, DateTime.Today);

                    if (dateTimeFailureMessage != string.Empty)
                    {
                        ModelState.AddModelError("", dateTimeFailureMessage);
                        return View(model);
                    }

                    var group = new Group { Name = model.Name, Description = model.Description, StartDate = model.StartDate, EndDate = model.EndDate };
                    context.Groups.Add(group);
                    context.SaveChanges();

                    return RedirectToAction("Index", "Group");
                }
                return RedirectToAction("Index", "Group");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 2
0
        public ActionResult Delete(int id, Group group)
        {
            try
            {
                group = context.Groups
                .Where(g => g.Id == group.Id)
                .FirstOrDefault();

                context.Groups.Remove(group);
                context.SaveChanges();

                return RedirectToAction("Index", "Group");
            }
            catch
            {
                return View();
            }
        }
Exemplo n.º 3
0
        private void watch_OnCreated(object source, FileSystemEventArgs e)
        {
            SmtpClient client = Functions.ConfigureSmtpClient();

            System.Configuration.Configuration Config =
                System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null);
            System.Configuration.KeyValueConfigurationElement mailReceiver =
                    Config.AppSettings.Settings["mailReceiver"];
            System.Configuration.KeyValueConfigurationElement mailSender =
                    Config.AppSettings.Settings["mailSender"];

            MailMessage message = new MailMessage();
            message.IsBodyHtml = false;
            MailAddress sender = new MailAddress("*****@*****.**");
            MailAddress receiver = new MailAddress("*****@*****.**");
            if (mailReceiver != null && mailSender != null)
            {
                receiver = new MailAddress(mailReceiver.Value);
                sender = new MailAddress(mailSender.Value);
            }
            ApplicationUser user = new ApplicationUser();
            if (userId != null || userId != string.Empty)
            {
                user = context.Users.Find(userId);
            }
            var group = new Group();

            if (user != null && user.GroupId.HasValue)
            {
                group = context.Groups.Find(user.GroupId);
                if (user.GroupId.HasValue)
                {
                    message.Body = "Nya inlämningsuppgifter har lagts till av " + user.FullName + ".";
                    message.Body += Environment.NewLine + "Grupp: " + group.Name;
                }
            }

            message.Sender = sender;
            message.To.Add(receiver);
            message.From = sender;
            message.Subject = "Inkomna inlämningsuppgifter";

            client.Send(message);
        }