Esempio n. 1
0
        public PageCreatedResponse CreatePage(PageRegistration pageRegistration)
        {
            try
            {
                var req = _pageRegBuilder.Build(pageRegistration);
                PageRegistrationConfirmation response = _jg.Page.Create(req);

                return new PageCreatedResponse
                    {
                        LoginTokenForEua = response.SignOnUrl,
                        PageId = response.PageId,
                        Successful = response.Error == null,
                        Message = response.Error != null ? response.Error.Description : "Page created",
                        PageShortName = pageRegistration.PageShortName,
                        Domain = ConfigurationManager.AppSettings["justGiving:RootDomain"]
                    };
            }
            catch (ErrorResponseException ex)
            {
                var errorIds = new List<string>();

                if (ex.Errors != null)
                {
                    errorIds = ex.Errors.Where(x => x != null).Select(error => error.Id).ToList();
                }

                return new PageCreatedResponse
                    {
                        Message = "Page creation failed. " + string.Join(", ", errorIds)
                    };
            }
        }
        public void Charity_ReturnsJsonResult()
        {
            var model = new PageRegistration();

            var result = _controller.Charity(1234);

            Assert.That(result, Is.TypeOf<JsonResult>());
        }
 public void SetUp()
 {
     _rprb = new RegisterPageRequestBuilder();
     _pageRegistration = new PageRegistration
     {
         Charity = new CharitySearchResult { Id = 123, Name = "My Charity" },
         DateOfBirth = "01/01/1950",
         DateOfDeath = "01/01/2000",
         FirstName = "Mary",
         Gender = Gender.Female,
         LastName = "Sue",
         PageShortName = "mary-sue",
         Image = new UserImageEntity { IsDefault = false, Url = "AUrl"}
     };
 }
        public ActionResult Create(PageRegistration pageRegistration)
        {
            if (!ModelState.IsValid)
            {
                return View(pageRegistration);
            }

            if (pageRegistration.Image.IsDefault)
            {
                var entity = _userImagesService.GetUsersDefaultImage();

                if (entity.IsDefault == false)
                {
                    entity = _userImagesService.GetUserImageEntityByUrl(pageRegistration.Image.Url);
                    entity.IsDefault = true;
                }
                else
                {
                    entity.Url = pageRegistration.Image.Url;
                }

                _userImagesService.SaveUserImageEntity(entity);
            }

            var response = _apiClient.CreatePage(pageRegistration);

            if (!response.Successful)
            {
                ModelState.AddModelError("General", Resources.CreateController_Create_Oooops);
                return View(pageRegistration);
            }

            _imageCleanup.BeginInvoke(null, null);

            _apiClient.GetPagesAsync(_currentUserSession.EmailAddress, _currentUserSession.UpdatePages);
            pageRegistration.LoginTokenForEua = response.LoginTokenForEua;
            pageRegistration.PageId = response.PageId;
            pageRegistration.Domain = response.Domain;

            TempData[pageRegistration.GetType().FullName] = pageRegistration;

            return RedirectToAction("AccountPage", "Account", new { @pageShortName = pageRegistration.PageShortName });
        }
        public JsonResult UploadFile(HttpPostedFileBase file, PageRegistration pageRegistration)
        {
            if (file.ContentLength > 4194304)
            {
                return Json(new { Error = "Cannot upload files bigger than 4MB in size. Please select a smaller image" });
            }

            var formats = new[] { ".jpg", ".png", ".gif", ".jpeg", ".bmp" };
            if (!file.ContentType.Contains("image") || !formats.Any(item => file.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase)))
            {
                return Json(new { Error = "Only image files of type JPEG, GIF, PNG or BMP can be uploaded" });
            }

            var image = new WebImage(file.InputStream) { FileName = file.FileName };
            return
               Json(
                   _userImagesService.SaveUserImageStream(
                       new MemoryStream(image.GetBytes()),
                       image.FileName,
                       image.ImageFormat, image.Height, image.Width),
                   "text/plain");
        }
        public ActionResult AccountPage(string pageShortName)
        {
            var pageRegistration = TempData[typeof(PageRegistration).FullName] as PageRegistration;

            if (pageRegistration == null)
            {
                var page = _currentUserSession.Pages.FirstOrDefault(x => x.PageShortName == pageShortName);
                if (page != null)
                {
                    var userImageEntity = new UserImageEntity
                    {
                        Url =
                            "http://justgiving.com/Utils/imaging.ashx?width=160&height=160&square=160&imageType=frpphoto&img="
                            + page.PageImages[0]
                    };
                    pageRegistration = new PageRegistration(
                        _apiClient.GetCharityById(int.Parse(page.CharityId)),
                        userImageEntity)
                    {
                        FirstName = page.InMemoryPerson.FirstName,
                        LastName = page.InMemoryPerson.LastName,
                        PageShortName = page.PageShortName,
                        DateOfDeath = page.InMemoryPerson.DateOfDeath.ToString(CultureInfo.InvariantCulture),
                        DateOfBirth = page.InMemoryPerson.DateOfBirth.ToString(CultureInfo.InvariantCulture),
                        Domain = ConfigurationManager.AppSettings["justGiving:RootDomain"],
                        CompanyName = _currentUserSession.OrganisationName
                    };
                    return View("Page", pageRegistration);
                }

            }
            else
            {
                return View("Page", pageRegistration);
            }

            return View("Account");
        }
        public void AccountPage_WhenTempDataHasObject_ReturnsPageViewWithObject()
        {
            var model = new PageRegistration();

            _controller.TempData[model.GetType().FullName] = model;

            var result = _controller.AccountPage("aPageShortName");

            Assert.That((result), Is.TypeOf<ViewResult>());
            Assert.That(((ViewResult)result).ViewName, Is.EqualTo("Page"));
            Assert.That(((ViewResult)result).Model, Is.EqualTo(model));
        }