Exemplo n.º 1
0
        public async Task <ActionResult> Edit()
        {
            //if (userContext.ContextName != UserContext.UserContextName.Organisation)
            //{
            //    return RedirectToAction("Index", "Home");
            //}

            Organisation organisation = await db.Organisations.FindAsync(userContext.ItemId);

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

            var   model = new AddEditOrganisationModel(organisation);
            Ukrlp ukrlp =
                db.Ukrlps.Include("PrimaryAddress")
                .Include("LegalAddress")
                .FirstOrDefault(x => x.Ukprn == organisation.UKPRN);

            if (ukrlp != null)
            {
                model.UKRLPData = new UKRLPDataModel(ukrlp);
            }

            // Populate the dropdowns
            GetLookups(model);

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Create(AddEditOrganisationModel model)
        {
            if (ModelState.IsValid)
            {
                Ukrlp ukrlp = db.Ukrlps.Find(model.UKPRN);
                if (ukrlp == null)
                {
                    // Don't tie error message to field as this will happen anyway when the script looks it up
                    ModelState.AddModelError("", AppGlobal.Language.GetText(this, "UKRLPNotFound", "UKRLP Not Found"));
                }
                else if (ukrlp.UkrlpStatus.HasValue && ukrlp.UkrlpStatus.Value == (Int32)Constants.RecordStatus.Deleted)
                {
                    // Don't tie error message to field as this will happen anyway when the script looks it up
                    ModelState.AddModelError("",
                                             AppGlobal.Language.GetText(this, "UKRLPDeactived", "UKRLP Has Been Deactivated"));
                }

                if (ProvisionUtilities.IsNameInUse(db, model.OrganisationName, null, null))
                {
                    ModelState.AddModelError("OrganisationName",
                                             AppGlobal.Language.GetText(this, "NameInUse",
                                                                        "This Organisation name already exists in the database, please contact the Course Directory Support Team on 0844 811 5073 or [email protected] if you need any help."));
                }

                if (ModelState.IsValid)
                {
                    Organisation organisation = model.ToEntity(db);
                    organisation.RecordStatu = db.RecordStatus.Find((int)Constants.RecordStatus.Live);
                    Address providerAddress = model.Address.ToEntity(db);
                    organisation.Address = providerAddress;
                    organisation.Address.ProviderRegionId = null;
                    if (userContext.IsProvider())
                    {
                        organisation.OrganisationProviders.Add(new OrganisationProvider
                        {
                            ProviderId = userContext.ItemId.Value,
                            IsAccepted = false,
                            IsRejected = false,
                        });
                    }
                    db.Addresses.Add(providerAddress);
                    db.Organisations.Add(organisation);
                    await db.SaveChangesAsync();

                    ShowGenericSavedMessage();
                    ProvisionUtilities.SendNewOrganisationEmail(organisation);
                    return(RedirectToAction("Index", "Home"));
                }
            }

            // Populate the drop downs
            GetLookups(model);

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Create()
        {
            var model = new AddEditOrganisationModel();

            model.Address.Populate(db);

            // Populate the drop downs
            GetLookups(model);

            return(View(model));
        }
Exemplo n.º 4
0
 private void GetLookups(AddEditOrganisationModel model)
 {
     model.Address.Populate(db);
     ViewBag.OrganisationTypes = new SelectList(
         db.OrganisationTypes,
         "OrganisationTypeId",
         "OrganisationTypeName",
         model.OrganisationTypeId);
     ViewBag.RecordStatuses = new SelectList(
         db.RecordStatus.Where(
             x =>
             x.RecordStatusId == (int)Constants.RecordStatus.Live ||
             x.RecordStatusId == (int)Constants.RecordStatus.Deleted),
         "RecordStatusId",
         "RecordStatusName",
         model.RecordStatusId);
     ViewBag.QualityEmailStatuses = new SelectList(
         db.QualityEmailStatuses,
         "QualityEmailStatusId",
         "QualityEmailStatusDesc",
         model.QualityEmailStatusId);
 }
Exemplo n.º 5
0
        public async Task <ActionResult> Details(int?id)
        {
            if (userContext.IsOrganisation())
            {
                id = id == userContext.ItemId || id == null ? userContext.ItemId : null;
            }

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

            var organisation = await db.Organisations.FindAsync(id);

            if (organisation == null || (userContext.IsProvider()
                                         &&
                                         !organisation.OrganisationProviders.Any(
                                             x =>
                                             x.OrganisationId == id && x.ProviderId == userContext.ItemId &&
                                             !x.IsRejected)))
            {
                return(HttpNotFound());
            }

            var model = new AddEditOrganisationModel(organisation, true);

            model.Populate(db);
            Ukrlp ukrlp =
                db.Ukrlps.Include("PrimaryAddress")
                .Include("LegalAddress")
                .FirstOrDefault(x => x.Ukprn == organisation.UKPRN);

            if (ukrlp != null)
            {
                model.UKRLPData = new UKRLPDataModel(ukrlp);
            }

            return(View(model));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Edit(AddEditOrganisationModel model)
        {
            if (Permission.HasPermission(false, true, Permission.PermissionName.CanEditProviderSpecialFields))
            {
                Ukrlp ukrlp = db.Ukrlps.Find(model.UKPRN);
                if (ukrlp == null)
                {
                    // Don't tie error message to field as this will happen anyway when the script looks it up
                    ModelState.AddModelError("", AppGlobal.Language.GetText(this, "UKRLPNotFound", "UKRLP Not Found"));
                }
                else if (ukrlp.UkrlpStatus.HasValue && ukrlp.UkrlpStatus.Value == (Int32)Constants.RecordStatus.Deleted &&
                         model.RecordStatusId.HasValue &&
                         model.RecordStatusId.Value != (Int32)Constants.RecordStatus.Deleted)
                {
                    // Don't tie error message to field as this will happen anyway when the script looks it up
                    ModelState.AddModelError("",
                                             AppGlobal.Language.GetText(this, "UKRLPDeactived", "UKRLP Has Been Deactivated"));
                }
            }

            if (ProvisionUtilities.IsNameInUse(db, model.OrganisationName, null, model.OrganisationId))
            {
                ModelState.AddModelError("OrganisationName",
                                         AppGlobal.Language.GetText(this, "NameInUse",
                                                                    "This Organisation name already exists in the database, please contact the Course Directory Support Team on 0844 811 5073 or [email protected] if you need any help."));
            }

            if (ModelState.IsValid)
            {
                Organisation organisation = model.ToEntity(db);
                if (organisation == null || organisation.OrganisationId != userContext.ItemId)
                {
                    return(HttpNotFound());
                }

                bool recordStatuschanged = model.RecordStatusId != organisation.RecordStatusId;
                if (
                    !(model.RecordStatusId == (int)Constants.RecordStatus.Live ||
                      model.RecordStatusId == (int)Constants.RecordStatus.Deleted))
                {
                    ModelState.AddModelError(
                        "RecordStatusId",
                        AppGlobal.Language.GetText("RecordStatusNotFound", "Status Is Invalid"));
                }

                if (recordStatuschanged &&
                    model.RecordStatusId == (int)Constants.RecordStatus.Deleted &&
                    organisation.OrganisationProviders.Any(x => x.IsAccepted && !x.IsRejected))
                {
                    ModelState.AddModelError(
                        "RecordStatusId",
                        AppGlobal.Language.GetText(this, "CannotDeleteActiveOrganisations",
                                                   "You may not delete this Organisation until all Providers have left or been removed."));
                }

                if (ModelState.IsValid)
                {
                    if (Permission.HasPermission(false, true, Permission.PermissionName.CanEditProviderSpecialFields))
                    {
                        organisation.UKPRN = model.UKPRN.HasValue ? model.UKPRN.Value : 0;
                        organisation.QualityEmailsPaused  = model.QualityEmailsPaused;
                        organisation.QualityEmailStatusId = model.QualityEmailStatusId;
                    }

                    organisation.ModifiedByUserId    = Permission.GetCurrentUserId();
                    organisation.ModifiedDateTimeUtc = DateTime.UtcNow;
                    // ReSharper disable once PossibleInvalidOperationException
                    organisation.RecordStatusId = model.RecordStatusId.Value;
                    Address organisationAddress = model.Address.ToEntity(db);

                    db.Entry(organisationAddress).State = EntityState.Modified;
                    db.Entry(organisation).State        = EntityState.Modified;
                    await db.SaveChangesAsync();

                    // Reset the user context if the status has changed
                    if (recordStatuschanged)
                    {
                        UserContext.SetUserContext(db, model.RecordStatusId == (int)Constants.RecordStatus.Deleted
                            ? UserContext.UserContextName.DeletedOrganisation
                            : UserContext.UserContextName.Organisation, userContext.ItemId, true);
                    }
                    ShowGenericSavedMessage();
                    return(RedirectToAction("Index", "Organisation"));
                }
            }

            // Populate the dropdowns
            GetLookups(model);

            return(View(model));
        }