//// GET: AppUsers/Edit/5
        //public ActionResult Edit()
        //{
        //    Guid id = AppUserHelpers.GetAppUserIdFromUser(User);
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    AppUser appUser = db.AppUsers.Find(id);
        //    if (appUser == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(appUser);
        //}

        //// POST: AppUsers/Edit/5
        //// To protect from overposting attacks, please enable the specific properties you want to bind to, for
        //// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        //[HttpPost]
        //[ValidateAntiForgeryToken]
        //public ActionResult Edit([Bind(Include = "AppUserId,FirstName,LastName,EntityStatus,OrganisationId,LoginEmail,PrivacyLevel,UserRole,MaxDistanceFilter,MaxAgeFilter,SelectionLevelFilter,DisplayMyOrganisationListingsFilter,RecordChange,RecordChangeOn,RecordChangeBy")] AppUser appUser)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        db.Entry(appUser).State = EntityState.Modified;
        //        db.SaveChanges();
        //        return RedirectToAction("Index");
        //    }
        //    return View(appUser);
        //}

        //// GET: AppUsers/Delete/5
        //public ActionResult Delete(Guid? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    AppUser appUser = db.AppUsers.Find(id);
        //    if (appUser == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(appUser);
        //}

        //// POST: AppUsers/Delete/5
        //[HttpPost, ActionName("Delete")]
        //[ValidateAntiForgeryToken]
        //public ActionResult DeleteConfirmed(Guid id)
        //{
        //    AppUser appUser = db.AppUsers.Find(id);
        //    db.AppUsers.Remove(appUser);
        //    db.SaveChanges();
        //    return RedirectToAction("Index");
        //}

        // GET: AppUsers/Profile/5
        public ActionResult UserProfile()
        {
            string errorMessage = "Your current user appears to be corrupt, please contact your system administrator.";
            Guid   id           = AppUserHelpers.GetAppUserIdFromUser(User);

            if (id == null)
            {
                return(RedirectToAction("Error", "Home", new { errorMessage = errorMessage }));
            }

            AppUserProfileView view = AppUserViewHelpers.CreateAppUserProfileView(id);

            if (view == null)
            {
                return(RedirectToAction("Error", "Home", new { errorMessage = errorMessage }));
            }

            //DropDown
            if (view.SelectedOrganisationId == Guid.Empty)
            {
                ViewBag.OrganisationList     = ControlHelpers.AllOrganisationsListDropDown(); //no selected item as nothing to select
                ViewBag.OrganisationSelected = false;
            }
            else
            {
                ViewBag.OrganisationList     = ControlHelpers.AllOrganisationsListDropDown(view.SelectedOrganisationId.Value); //select the organisation as initial value
                ViewBag.OrganisationSelected = true;
            }

            return(View(view));
        }
        // GET: AppUsers/Settings/5
        public ActionResult Settings()
        {
            string errorMessage = "Your current user appears to be corrupt, please contact your system administrator.";
            Guid   id           = AppUserHelpers.GetAppUserIdFromUser(User);

            if (id == null)
            {
                return(RedirectToAction("Error", "Home", new { errorMessage = errorMessage }));
            }

            AppUserSettingsView view = AppUserViewHelpers.CreateAppUserSettingsView(id);

            if (view == null)
            {
                return(RedirectToAction("Error", "Home", new { errorMessage = errorMessage }));
            }

            return(View(view));
        }
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                AppUserHelpers.UpdateAppUserEntityStatusIfForcedPasswordChange(AppUserHelpers.GetAppUserIdFromUser(User), User);
                return(RedirectToAction("Index", "Home"));
            }
            AddErrors(result);
            return(View(model));
        }
Beispiel #4
0
        // GET: Groups
        public ActionResult Index()
        {
            GroupEditView model = GroupViewHelpers.GetGroupEditViewForUser(db, AppUserHelpers.GetAppUserIdFromUser(User));

            return(View(model));

            //This view will do everything.
            //List all groups you belong to
            //List all your 'friends' groups
            //List the 'requests' to join your group for approval
            //Allow you to 'add' a new group
            //Allow you to remove 'your' group (you are group admin)
            //Allow you to 'request' a friend join your group (on them saying yes it automatically adds them)
            //Allow you to 'join' a friends group (on them saying yes it automatically adds you)

            //PS Need to add the 'friend request' stuff also. - i.e.
            //Friend table that holds type (User, branch, company) and Id.
            //- on company admin it will show company friends and give 'admin' the ability to add/remove etc..
            //- on branch admin it will show branch friends and give 'admin' & 'manager' the ability to add/remove etc.
            //- on user it will show user friends and give all ability to add/remove etc..
            //.....therefore 'add friend' on listings page highlighting company/branch/user need to be displayed for those with right access.
            //.....this will then go off for approval
        }
        // GET: RequirementListings/Edit/5
        public ActionResult Edit(Guid?id, bool showHistory)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            RequirementListingEditView requirementListing = RequirementListingEditHelpers.GetRequirementListingEditView(db, id.Value, User);

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

            ViewBag.CampaignList = ControlHelpers.AllActiveCampaignsForUserListDropDown(AppUserHelpers.GetAppUserIdFromUser(User), requirementListing.SelectedCampaignId);
            ViewBag.ShowHistory  = showHistory;

            return(View(requirementListing));
        }
        public ActionResult Create([Bind(Include = "ItemDescription,ItemType,QuantityRequired,QuantityFulfilled,QuantityOutstanding,UoM,RequiredFrom,RequiredTo,AcceptDamagedItems,AcceptOutOfDateItems,CollectionAvailable,ListingStatus,SelectedCampaignId,CallingAction,CallingController")] RequirementListingAddView requirementListing)
        {
            if (ModelState.IsValid)
            {
                RequirementListingHelpers.CreateRequirementListingFromRequirementListingAddView(db, requirementListing, User);

                return(RedirectToAction(requirementListing.CallingAction, requirementListing.CallingController));
            }

            ViewBag.CampaignList = ControlHelpers.AllActiveCampaignsForUserListDropDown(AppUserHelpers.GetAppUserIdFromUser(User), null);
            return(View(requirementListing));
        }
        // GET: RequirementListings/Create
        public ActionResult Create()
        {
            string callingController = "Home";
            string callingAction     = "Index";

            try
            {
                string[] callingUrlSegments = Request.UrlReferrer.Segments.Select(x => x.TrimEnd('/')).ToArray();
                callingController = callingUrlSegments[callingUrlSegments.Count() - 2];
                callingAction     = callingUrlSegments[callingUrlSegments.Count() - 1];
            }
            catch { }

            ViewBag.CallingController = callingController;
            ViewBag.CampaignList      = ControlHelpers.AllActiveCampaignsForUserListDropDown(AppUserHelpers.GetAppUserIdFromUser(User), null);

            RequirementListingAddView model = new RequirementListingAddView()
            {
                CallingAction     = callingAction,
                CallingController = callingController
            };

            return(View(model));
        }
        public ActionResult Edit([Bind(Include = "ListingId,ItemDescription,ItemType,QuantityRequired,QuantityFulfilled,QuantityOutstanding,UoM,RequiredFrom,RequiredTo,AcceptDamagedItems,AcceptOutOfDateItems,CollectionAvailable,ListingStatus,SelectedCampaignId,CampaignName,CampaignStrapLine,CampaignDescription,CampaignStartDateTime,CampaignEndDateTime")] RequirementListingEditView requirementListing)
        {
            if (ModelState.IsValid)
            {
                //If the 'Submit' button pressed then update tables, else leave as are so that on reload it takes original values once again.
                if (Request.Form["submitbutton"] != null)
                {
                    //Update tables
                    RequirementListingHelpers.UpdateRequirementListingFromRequirementListingEditView(db, requirementListing);

                    return(RedirectToAction("Requirements", "ManageListings"));
                }

                return(RedirectToAction("Edit"));
            }

            //rebuild the missing details before returning to screen to show errors
            RequirementListing listing = RequirementListingHelpers.GetRequirementListing(db, requirementListing.ListingId);

            requirementListing.ListingAppUser       = AppUserHelpers.GetAppUser(db, listing.ListingOriginatorAppUserId);
            requirementListing.ListingBranchDetails = BranchHelpers.GetBranch(db, listing.ListingOriginatorAppUserId);

            //Rebuild campaign details as changing will change ID but no address details, so force the change now:
            if (requirementListing.SelectedCampaignId != null)
            {
                Campaign campaign = CampaignHelpers.GetCampaign(db, requirementListing.SelectedCampaignId.Value);
                requirementListing.CampaignName          = campaign.Name;
                requirementListing.CampaignStrapLine     = campaign.StrapLine;
                requirementListing.CampaignDescription   = campaign.Description;
                requirementListing.CampaignStartDateTime = campaign.CampaignStartDateTime;
                requirementListing.CampaignEndDateTime   = campaign.CampaignEndDateTime;
            }

            ViewBag.CampaignList = ControlHelpers.AllActiveCampaignsForUserListDropDown(AppUserHelpers.GetAppUserIdFromUser(User), requirementListing.SelectedCampaignId);

            return(View(requirementListing));
        }