Example #1
0
 public ActionResult Edit(Resource model)
 {
     if (this.ModelState.IsValid)
     {
         dc.Entry(model).State = System.Data.Entity.EntityState.Modified;
         dc.SaveChanges();
         return(this.RedirectToAction("Index"));
     }
     ViewBag.Title        = "Editace zdroje";
     ViewBag.CancelAction = "Index";
     return(View("~/Views/Shared/UniversalEditor.cshtml", model));
 }
Example #2
0
        public ActionResult Delete(int bookingId, object fake)
        {
            var b = dc.Bookings.SingleOrDefault(x => x.BookingId == bookingId && x.User.UserName.Equals(this.User.Identity.Name));

            if (b == null)
            {
                return(this.HttpNotFound());
            }

            dc.Bookings.Remove(b);
            dc.SaveChanges();

            return(this.RedirectToAction("MyBookings"));
        }
Example #3
0
        public ActionResult Create(CreateMessageViewModel model)
        {
            if (this.TryUpdateModel(model))
            {
                // Get ID of current user
                var userId = dc.Users.Single(x => x.UserName.Equals(this.User.Identity.Name)).UserId;

                // Create new message
                dc.Messages.Add(new Message {
                    Body        = model.Body,
                    DateCreated = DateTime.Now,
                    Subject     = model.Subject,
                    UserId      = userId
                });
                dc.SaveChanges();

                // Send message
                if (RuntimeOptions.Current.UseMailing)
                {
                    var accountUri = new UriBuilder(this.Request.Url)
                    {
                        Path = this.Url.Action("Index", "Account"), Query = "", Fragment = ""
                    };
                    var recipients = from u in dc.Users
                                     where u.UserId != userId && u.IsApproved && u.EmailMessages
                                     select u.Email;
                    Mailer.SendMail(recipients, Properties.Resources.MessageCreateSubject, Properties.Resources.MessageCreateBody,
                                    model.Subject,           // 0
                                    this.User.Identity.Name, // 1
                                    model.Body,              // 2
                                    accountUri);             // 3
                }

                return(this.RedirectToAction("Index"));
            }

            ViewBag.Title            = "Nová zpráva";
            ViewBag.CancelAction     = "Index";
            ViewBag.CancelController = "Messages";
            return(View("~/Views/Shared/UniversalEditor.cshtml", model));
        }
Example #4
0
        public void InitializeApplicationData()
        {
            // Set runtime options; this also creates ~/App_Data/ folder
            RuntimeOptions.Current.ApplicationTitle = this.ApplicationTitle;
            RuntimeOptions.Current.Save();

            // Create new resource; this also creates the database
            using (var dc = new RapDbContext()) {
                dc.Resources.Add(new Resource {
                    Name = this.FirstResourceName
                });
                dc.SaveChanges();
            }

            // Update parameters of user 'Administrator'
            var admin        = Membership.GetUser("Administrator", false);
            var tempPassword = admin.ResetPassword();

            admin.ChangePassword(tempPassword, this.AdministratorPassword);
            admin.Email = this.AdministratorEmail;
            Membership.UpdateUser(admin);
        }
Example #5
0
        public ActionResult Index(AccountViewModel model)
        {
            if (this.TryUpdateModel(model))
            {
                if (!Membership.ValidateUser(this.User.Identity.Name, model.CurrentPassword))
                {
                    // Invalid password
                    this.ModelState.AddModelError("CurrentPassword", "Současné heslo je chybné");
                }
                else
                {
                    // Update e-mail
                    var membershipUser = Membership.GetUser();
                    membershipUser.Email = model.EmailAddress;
                    Membership.UpdateUser(membershipUser);

                    // Update password
                    if (!string.IsNullOrWhiteSpace(model.NewPassword))
                    {
                        membershipUser.ChangePassword(model.CurrentPassword, model.NewPassword);
                    }

                    // Update options
                    var user = dc.Users.Single(x => x.UserName.Equals(this.User.Identity.Name));
                    user.EmailBookings = model.EmailBookings;
                    user.EmailMessages = model.EmailMessages;
                    dc.SaveChanges();

                    return(RedirectToAction("Index", "Home"));
                }
            }
            ViewBag.Title            = "Moje nastavení";
            ViewBag.CancelAction     = "Index";
            ViewBag.CancelController = "Home";
            return(View("~/Views/Shared/UniversalEditor.cshtml", model));
        }