Esempio n. 1
0
        public async Task <ActionResult> Edit()
        {
            var professional = _professionalQueries.GetUiDto_ProfessionalFromUserGuid(User.Identity.GetUserId());

            if (professional == null)
            {
                // Create the professional. If there's a linking key, don't worry about it for now.
                professional = new ProfessionalUiDto();
                professional.ProfessionalId     = new Guid();
                professional.ProfessionalUserId = AppointmentsDb.Helpers.GuidHelper.GetGuid(User.Identity.GetUserId());
                professional.EmailAddress       = User.Identity.Name;
            }
            else
            {
                // If there's a pending key to link the pro to the company, do it.
                var specialKey = new Helpers.Cookies().GetCookieAndDelete(this, Helpers.Cookies.CompanyLinkingKeyCookieName);
                if (!string.IsNullOrWhiteSpace(specialKey))
                {
                    var success = await Task.Run(() => _linkingKeyQueries.UseLinkingKey_AddProfessionalToCompany(User.Identity.GetUserId(), specialKey));

                    return(RedirectToAction("UseCompanyKeyComplete", "LK", new { isSuccess = success }));
                }
            }

            return(View(professional));
        }
        // GET: CompanyProfile/Edit/5
        public async Task <ActionResult> Edit(Guid?id)
        {
            var company = _companyQueries.GetUiDto_CompanyFromUserGuid(User.Identity.GetUserId());

            // If there's a pending key to link the pro to the company, do it.
            var specialKey = new Helpers.Cookies().GetCookieAndDelete(this, Helpers.Cookies.CompanyLinkingKeyCookieName);

            if (!string.IsNullOrWhiteSpace(specialKey))
            {
                var success = await Task.Run(() => _linkingKeyQueries.UseLinkingKey_AddProfessionalToCompany(User.Identity.GetUserId(), specialKey));

                return(RedirectToAction("UseCompanyKeyComplete", "LK", new { isSuccess = success }));
            }

            // If they are not the owner, don't allow them to edit.
            if (company != null && !company.UILoadOnly_IsUserCompanyOwner)
            {
                return(RedirectToAction("Details", "CompanyProfile"));
            }

            // new company
            if (company == null)
            {
                var pro = _professionalQueries.GetUiDto_ProfessionalFromUserGuid(User.Identity.GetUserId());
                company = new AppointmentsDb.ModelsDto.CompanyUiDto();
                company.MainContactEmail = pro.EmailAddress;
                company.MainContactName  = pro.Honorific + " " + pro.Forename + " " + pro.Surname + " " + pro.Suffix;
            }

            return(View(company));
        }