Пример #1
0
        //// 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));
        }
Пример #2
0
        //AppUser/Profile
        public static AppUserProfileView CreateAppUserProfileView(Guid appUserId)
        {
            ApplicationDbContext db   = new ApplicationDbContext();
            AppUserProfileView   view = CreateAppUserProfileView(db, appUserId);

            db.Dispose();
            return(view);
        }
Пример #3
0
        //updates AppUser from the AppUserProfileView (AppUser/UserProfile)
        public static AppUser UpdateAppUser(AppUserProfileView view, IPrincipal user, bool organisationDetailsExsits)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            AppUser appUser         = UpdateAppUser(db, view, user, organisationDetailsExsits);

            db.Dispose();
            return(appUser);
        }
Пример #4
0
        //AppUser/Profile
        public static AppUserProfileView CreateAppUserProfileView(ApplicationDbContext db, Guid appUserId)
        {
            AppUser appUser = AppUserHelpers.GetAppUser(db, appUserId);

            if (appUser == null)
            {
                return(null);
            }

            AppUserProfileView view = new AppUserProfileView()
            {
                AppUserId              = appUser.AppUserId,
                FirstName              = appUser.FirstName,
                LastName               = appUser.LastName,
                EntityStatus           = appUser.EntityStatus,
                LoginEmail             = appUser.LoginEmail,
                PrivacyLevel           = appUser.PrivacyLevel,
                UserRole               = appUser.UserRole,
                SelectedOrganisationId = appUser.OrganisationId
            };

            if (appUser.OrganisationId != Guid.Empty)
            {
                Organisation org = OrganisationHelpers.GetOrganisation(db, appUser.OrganisationId);
                view.OrganisationName = org.OrganisationName;
                view.BusinessType     = org.BusinessType;
                view.AddressLine1     = org.AddressLine1;
                view.AddressLine2     = org.AddressLine2;
                view.AddressLine3     = org.AddressLine3;
                view.AddressTownCity  = org.AddressTownCity;
                view.AddressCounty    = org.AddressCounty;
                view.AddressPostcode  = org.AddressPostcode;
            }

            return(view);
        }
Пример #5
0
        //updates AppUser from the AppUserProfileView (AppUser/UserProfile)
        public static AppUser UpdateAppUser(ApplicationDbContext db, AppUserProfileView view, IPrincipal user, bool organisationDetailsExsits)
        {
            AppUser appUser = GetAppUser(db, view.AppUserId);

            appUser.FirstName      = view.FirstName;
            appUser.LastName       = view.LastName;
            appUser.RecordChange   = RecordChangeEnum.RecordUpdated;
            appUser.RecordChangeBy = GetAppUserIdFromUser(user);
            appUser.RecordChangeOn = DateTime.Now;

            if (!organisationDetailsExsits)
            {
                appUser.EntityStatus   = view.EntityStatus;
                appUser.LoginEmail     = view.LoginEmail;
                appUser.PrivacyLevel   = view.PrivacyLevel;
                appUser.UserRole       = view.UserRole;
                appUser.OrganisationId = view.SelectedOrganisationId.Value;
            }

            db.Entry(appUser).State = EntityState.Modified;
            db.SaveChanges();

            return(appUser);
        }
Пример #6
0
        public ActionResult UserProfile([Bind(Include = "AppUserId,FirstName,LastName,EntityStatus,LoginEmail,PrivacyLevel,UserRole,SelectedOrganisationId,OrganisationName,BusinessType,AddressLine1,AddressLine2,AddressLine3,AddressTownCity,AddressCounty,AddressPostcode")] AppUserProfileView view)
        {
            if (Request.Form["resetbutton"] != null)
            {
                return(RedirectToAction("UserProfile"));
            }

            if (ModelState.IsValid)
            {
                //if selectedorganisationid is null then the organisation already exists so set that flag as a limited number of fields needs updating

                if (view.SelectedOrganisationId == null)
                {
                    AppUserHelpers.UpdateAppUser(db, view, User, true);
                }
                else
                {
                    AppUserHelpers.UpdateAppUser(db, view, User, false);
                }

                return(RedirectToAction("Dashboard", "Home"));
            }
            return(View(view));
        }