public ActionResult ChangePassword(int id, ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
                : "";

            TranyrMembershipDb usersContext = new TranyrMembershipDb();
            UserProfile        User         = usersContext.UserProfiles.Find(id);

            LocalPasswordModel localPasswordModel = new LocalPasswordModel();

            localPasswordModel.UserName = User.UserName;

            ViewBag.DisplayName = User.DisplayName;

            return(View(localPasswordModel));
        }
        public ActionResult Edit(UserProfile userProfile)
        {
            using (TranyrMembershipDb userDb = new TranyrMembershipDb())
            {
                UserProfile currentUserProfile = userDb.UserProfiles.Find(userProfile.UserId);
                if (currentUserProfile.UserName != userProfile.UserName)
                {
                    RedirectToAction("Error");
                }
                userProfile.CreateDate = currentUserProfile.CreateDate;
            }

            if (ModelState.IsValid)
            {
                db.Entry(userProfile).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userProfile));
        }
        public ActionResult AssignShipmentToUser(int id, string username)
        {
            Shipment shipment = db.Shipments.Find(id);

            if (shipment == null)
            {
                return(HttpNotFound());
            }

            using (TranyrMembershipDb userDb = new TranyrMembershipDb())
            {
                UserProfile userProfile = userDb.UserProfiles.FirstOrDefault(x => x.UserName == username);
                if (!Roles.IsUserInRole(userProfile.UserName, "Manager") || !Roles.IsUserInRole(userProfile.UserName, "Operator"))
                {
                    return(HttpNotFound());
                }
            }

            shipment.AssignedTo = username;

            return(this.Edit(shipment));
        }
        public ActionResult AssignEnquiryToUser(int id, string username)
        {
            Enquiry enquiry = db.Enquiries.Find(id);

            if (enquiry == null)
            {
                return(HttpNotFound());
            }

            using (TranyrMembershipDb userDb = new TranyrMembershipDb())
            {
                UserProfile userProfile = userDb.UserProfiles.FirstOrDefault(x => x.UserName == username);
                if (!Roles.IsUserInRole(userProfile.UserName, "Manager") || !Roles.IsUserInRole(userProfile.UserName, "Customer-Service"))
                {
                    return(HttpNotFound());
                }
            }

            enquiry.AssignedTo = username;

            return(this.Edit(enquiry));
        }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer <TranyrMembershipDb>(null);

                try
                {
                    using (var context = new TranyrMembershipDb())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }
                    if (!WebSecurity.Initialized)
                    {
                        WebSecurity.InitializeDatabaseConnection("TranyrMembershipDb", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }