Ejemplo n.º 1
0
        private static async Task <SponsorResults> GetSponsor(string sponsorID)
        {
            APIService   srv              = new APIService();
            SponsorModel model            = new SponsorModel();
            Dictionary <string, string> p = new Dictionary <string, string>();

            p.Add("id", string.Format("'{0}'", sponsorID));

            model.CommandModel.SessionToken = await App.GetUsersSession();

            model.CommandModel.ServiceName = "Sponsor";
            model.CommandModel.Action      = "GetById";
            model.CommandModel.Parameters  = p;

            SponsorResults result = null;
            var            cache  = BlobCache.UserAccount;
            var            cachedSponsorPromise = cache.GetAndFetchLatest(
                sponsorID,
                () => srv.GetSponsorById(model.CommandModel),
                offset =>
            {
                TimeSpan elapsed = DateTimeOffset.Now - offset;
                return(elapsed > new TimeSpan(hours: 0, minutes: 10, seconds: 0));
            });

            cachedSponsorPromise.Subscribe(subscribedSponsor =>
            {
                result = subscribedSponsor;
            });

            result = await cachedSponsorPromise.FirstOrDefaultAsync();

            return(result);
        }
Ejemplo n.º 2
0
        public async void GetSponsorsForEvent_Test()
        {
            APIService   srv      = new APIService();
            SponsorModel model    = new SponsorModel();
            EventModel   evtmodel = new EventModel();

            evtmodel.CommandModel.SessionToken = "bfc223c67931041556d324e25ee98cd0818dc6370486291d925127b1f5cd90ef";
            evtmodel.CommandModel.Action       = "GetOpenEvents";

            var res = await srv.GetEvents(evtmodel.CommandModel);

            if (res.Status == "OK" && res.Data != null)
            {
                Dictionary <string, string> p = new Dictionary <string, string>();
                p.Add("eventId", string.Format("'{0}'", res.Data.FirstOrDefault().Id));

                model.CommandModel.SessionToken = "bfc223c67931041556d324e25ee98cd0818dc6370486291d925127b1f5cd90ef";
                model.CommandModel.ServiceName  = "Sponsor";
                model.CommandModel.Action       = "GetSponsorsForEvent";
                model.CommandModel.Parameters   = p;

                var r = await srv.GetSponsorsForEvent(model.CommandModel);

                Assert.True(r.Status == "OK" && r.Data != null);
            }
            else
            {
                Assert.IsTrue(false);
            }
        }
Ejemplo n.º 3
0
        public ActionResult AssignAllStudiesToUser(SponsorModel Model)
        {
            List <StudyPermission> removestudypermissions = new List <StudyPermission>();

            try
            {
                foreach (SponsorPermissionModel s in Model.SponsorPermissions)
                {
                    if (s.Remove == false)
                    {
                        List <Study>           studies          = new List <Study>();
                        List <StudyPermission> studypermissions = new List <StudyPermission>();
                        studies = studymanager.GetStudiesBySponsorID(s.SponsorID);

                        foreach (Study s1 in studies)
                        {
                            StudyPermission sp = new StudyPermission();
                            sp.UserID    = Model.id;
                            sp.SponsorID = s.SponsorID;
                            sp.Status    = s.ShowAllStudies;
                            sp.StudyID   = s1.StudyID;
                            studypermissions.Add(sp);
                        }

                        if (studymanager.InsertStudyPermission(studypermissions))
                        {
                            ViewBag.message = "Changes saved";
                        }
                    }
                    else
                    {
                        sponsormanager.RemoveAssignedSponsors(s.SponsorID, Model.id);

                        StudyPermission sp = new StudyPermission();
                        sp.UserID    = Model.id;
                        sp.SponsorID = s.SponsorID;
                        removestudypermissions.Add(sp);
                    }
                }
                if (removestudypermissions.Count != 0)
                {
                    if (studymanager.RemoveStudyPermission(removestudypermissions))
                    {
                        ViewBag.message = "removed";
                    }
                }
                return(View("Sponsor_StudyManagement"));
            }
            catch (Exception e)
            {
                ViewBag.message = e.Message;
                return(View("Error"));
            }
        }
        public ActionResult Index(List <string> Sponsors)
        {
            SponsorModel model = new SponsorModel();

            model.id = id1;
            model.SponsorPermissions = new List <SponsorPermissionModel>();
            List <Sponsor> assignedsponsors = new List <Sponsor>();

            try
            {
                if (Sponsors.Count != 0)
                {
                    sponsorManager.AssignSponsorToUser(Sponsors, id1);

                    assignedsponsors = sponsorManager.GetAssignedSponsors(id1);


                    foreach (Sponsor s1 in assignedsponsors)
                    {
                        SponsorPermissionModel spm = new SponsorPermissionModel();
                        spm.SponsorID      = s1.SponsorID;
                        spm.SponsorName    = s1.SponsorName;
                        spm.ShowAllStudies = studyManager.CheckStudyPermission(id1, s1.SponsorID);

                        model.SponsorPermissions.Add(spm);
                    }
                }

                else
                {
                    assignedsponsors = sponsorManager.GetAssignedSponsors(id1);
                    foreach (Sponsor s1 in assignedsponsors)
                    {
                        SponsorPermissionModel spm = new SponsorPermissionModel();
                        spm.SponsorID      = s1.SponsorID;
                        spm.SponsorName    = s1.SponsorName;
                        spm.ShowAllStudies = studyManager.CheckStudyPermission(id1, s1.SponsorID);
                        model.SponsorPermissions.Add(spm);
                    }
                }


                return(PartialView("_sponsors", model));
            }
            catch (NullReferenceException ex)
            {
                return(Redirect(FormsAuthentication.LoginUrl));
            }
            catch (Exception ex)
            {
                ViewBag.message = ex.Message;
                return(View("Error"));
            }
        }
Ejemplo n.º 5
0
 public override void FuncPreInitEditView(object id, ref Sponsor EditItem, ref SponsorEditModel model)
 {
     if (EditItem == null)
     {
         //get the item by id
         EditItem = new SponsorModel <Sponsor>().Get(id);
     }
     if (EditItem != null)
     {
         model          = new SponsorEditModel();
         model.EditItem = EditItem;
     }
 }
Ejemplo n.º 6
0
        public override void FuncPreDetailsView(object id, ref List <SponsorDetailsViewModel> items)
        {
            filters = new List <GenericDataFormat.FilterItems>();
            filters.Add(new GenericDataFormat.FilterItems()
            {
                Property = "SponsorID", Operation = GenericDataFormat.FilterOperations.Equal, Value = id
            });
            var requestBody = new GenericDataFormat()
            {
                Filters = filters
            };

            items = new SponsorModel <SponsorDetailsViewModel>().Get(requestBody);
        }
Ejemplo n.º 7
0
        public async void GetSponsorForEvent_Test()
        {
            APIService   srv      = new APIService();
            SponsorModel model    = new SponsorModel();
            EventModel   evtmodel = new EventModel();

            Dictionary <string, string> p = new Dictionary <string, string>();

            p.Add("id", string.Format("'{0}'", "4b920877-6c43-45ad-a5bf-3d63a1e80171"));

            model.CommandModel.SessionToken = "bd95daab54ea3f8039b2521c50590b6e98d18bb7ad1242bee64216853bf2f6d2";
            model.CommandModel.ServiceName  = "Sponsor";
            model.CommandModel.Action       = "GetById";
            model.CommandModel.Parameters   = p;

            var r = await srv.GetSponsorById(model.CommandModel);

            Assert.True(r.Status == "OK" && r != null);
        }
Ejemplo n.º 8
0
        public async void GetSpeakerForEvent_Test()
        {
            APIService   srv      = new APIService();
            SponsorModel model    = new SponsorModel();
            EventModel   evtmodel = new EventModel();

            Dictionary <string, string> p = new Dictionary <string, string>();

            p.Add("id", string.Format("'{0}'", "5ef950ed-db6a-4592-a53a-8c91b44910bf"));

            model.CommandModel.SessionToken = "bd95daab54ea3f8039b2521c50590b6e98d18bb7ad1242bee64216853bf2f6d2";
            model.CommandModel.ServiceName  = "Speaker";
            model.CommandModel.Action       = "GetById";
            model.CommandModel.Parameters   = p;

            var r = await srv.GetSpeakerById(model.CommandModel);

            Assert.True(r.Status == "OK" && r != null);
        }
        public IHttpActionResult SaveSponsor(SponsorModel requestModel)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Invalid Data" }));
            }

            var battle = _videoBattleService.Get(requestModel.BattleId); //todo: query picture battles when ready

            if (battle == null)
            {
                return(Json(new { Success = false, Message = "Invalid Battle" }));
            }

            var isProductOnlySponsorship = requestModel.SponsorshipType == SponsorshipType.OnlyProducts;

            var userId = ApplicationContext.Current.CurrentUser.Id;

            //there is a possibility that a sponsor is increasing the sponsorship amount. In that case, the new sponsorship status will automatically
            //be of same status as that of previous one for the same battle
            //lets find if the sponsor already exist for this battle?
            var existingSponsors = _sponsorService.GetSponsors(userId, requestModel.BattleId, requestModel.BattleType, null);

            var newSponsorStatus = SponsorshipStatus.Pending;

            //so is the current customer already an sponsor for this battle?
            if (existingSponsors.Any())
            {
                newSponsorStatus = existingSponsors.First().SponsorshipStatus;
            }

            if (!isProductOnlySponsorship)
            {
                //are issued credits sufficient?
                var issuedCreditsCount = _creditService.GetUsableCreditsCount(userId);
                if ((issuedCreditsCount < battle.MinimumSponsorshipAmount && newSponsorStatus != SponsorshipStatus.Accepted) || requestModel.SponsorshipCredits > issuedCreditsCount)
                {
                    VerboseReporter.ReportError("Insufficient credits to become sponsor", "save_sponsor");
                    return(RespondFailure());
                }
            }

            //mark the credits as spent credits
            var spentCredit = new Credit()
            {
                CreditContextKey      = string.Format(CreditContextKeyNames.BattleSponsor, battle.Id),
                CreditCount           = requestModel.SponsorshipCredits,
                CreditTransactionType = CreditTransactionType.Spent,
                CreditType            = CreditType.Transactional,
                PaymentTransactionId  = 0,
                CreatedOnUtc          = DateTime.UtcNow,
                UserId = userId
            };

            _creditService.Insert(spentCredit);

            //create the sponsor and set the status to pending or an existing status as determined above. (the status will be marked accepted or rejected or cancelled by battle owner)
            var sponsor = new Sponsor()
            {
                BattleId          = requestModel.BattleId,
                BattleType        = requestModel.BattleType,
                SponsorshipAmount = isProductOnlySponsorship ? 0 : requestModel.SponsorshipCredits,
                UserId            = userId,
                SponsorshipStatus = newSponsorStatus,
                DateCreated       = DateTime.UtcNow,
                DateUpdated       = DateTime.UtcNow
            };

            //save the sponsor
            _sponsorService.Insert(sponsor);

            if (!isProductOnlySponsorship)
            {
                //save the prizes only sponsorship prizes
                SaveSponsorProductPrizes(requestModel.Prizes);
            }


            var battleOwner = _userService.Get(battle.ChallengerId);

            var sponsorCustomer = _userService.Get(userId);

            //send notification to battle owner
            _emailSender.SendSponsorAppliedNotificationToBattleOwner(battleOwner, sponsorCustomer, battle);

            return(Json(new { Success = true }));
        }
Ejemplo n.º 10
0
        // POST: Dynamic Academic page.
        public ActionResult StoreSponsorPage(SponsorModel sponsor)
        {
            bool edit = false;

            if (sponsor.SponsorTextField == null)
            {
                sponsor = DatabaseHelper.GetSponsorData(sponsor, WebSecurity.GetUserId(User.Identity.Name));

                sponsor.SponsorTextField = "";

                if (DatabaseHelper.StoreSponsorData(sponsor, ref edit))
                {
                    TempData["Message"] = "Successfully deleted your information as a sponsor.";
                    return RedirectToAction("Index", "Sponsors");
                }

                else
                {
                    TempData["Message"] = "Failed to delete your information as a sponsor.";
                    return RedirectToAction("Index", "Sponsors");
                }
            }

            else
            {
                SponsorModel currentSponsor = new SponsorModel();

                currentSponsor = DatabaseHelper.GetSponsorData(currentSponsor, WebSecurity.GetUserId(User.Identity.Name));

                string newTextField = sponsor.SponsorTextField;

                sponsor = currentSponsor;

                sponsor.SponsorTextField = newTextField;

                if (DatabaseHelper.StoreSponsorData(sponsor, ref edit))
                {
                    TempData["Message"] = "Successfully entered your information as a sponsor.";
                    return RedirectToAction("Index", "Sponsors");
                }

                else
                {
                    TempData["Message"] = "Failed to enter your information as a sponsor.";
                    return RedirectToAction("Index", "Sponsors");
                }
            }
        }
Ejemplo n.º 11
0
        public ActionResult StoreSponsor(SponsorModel sponsor)
        {
            if (ModelState.IsValid)
            {
                bool edit = false;

                if (sponsor.AccountStatus < 1)
                {
                    sponsor.AccountStatus = 1;
                }

                else if (sponsor.AccountStatus > 3)
                {
                    sponsor.AccountStatus = 3;
                }

                if (sponsor.SponsorTextField == null && WebSecurity.GetUserId(sponsor.EmailAddress) > 0)
                {
                    SponsorModel oldSponsor = new SponsorModel();

                    string field = DatabaseHelper.GetSponsorData(oldSponsor, WebSecurity.GetUserId(sponsor.EmailAddress)).SponsorTextField;

                    sponsor.SponsorTextField = field;
                }

                if (DatabaseHelper.StoreSponsorData(sponsor, ref edit))
                {
                    int ID = WebSecurity.GetUserId(sponsor.EmailAddress);

                    if (edit == true && ID != WebSecurity.CurrentUserId)
                    {
                        TempData["Message"] = "Successfully edited the user's information.";

                        return RedirectToAction("User", "Admin", new { ID });
                    }

                    if (edit == true)
                    {
                        TempData["Message"] = "Successfully edited your information.";
                        return RedirectToAction("Manage", "Account");
                    }

                    else
                    {
                        TempData["Message"] = "Thank you for registering to IT in the D. You will be contacted within 24-48 hours.";
                        return RedirectToAction("ThankYou", "Home");
                    }
                }

                else
                {
                    TempData["Message"] = "Registeration failed.";
                    return RedirectToAction("DisplaySponsor", "Account");
                }
            }

            TempData["Message"] = "Registeration failed.";
            return RedirectToAction("DisplaySponsor", "Account");
        }
Ejemplo n.º 12
0
        // GET: Dynamic Academic page.
        public ActionResult DisplaySponsorPage()
        {
            SponsorModel currentSponsor = new SponsorModel();

            currentSponsor = DatabaseHelper.GetSponsorData(currentSponsor, WebSecurity.GetUserId(User.Identity.Name));

            return View(currentSponsor);
        }
Ejemplo n.º 13
0
        public ActionResult DisplaySponsor()
        {
            SponsorModel spons = new SponsorModel();
            if (DatabaseHelper.GetSponsorData(spons, -1) == null)
            {
                TempData["RegistrationMessage"] = "Corporate Sponsor registration form.";
            }

            return View(spons);
        }
Ejemplo n.º 14
0
        //==================================================================================//
        //      Get Sponsor information                                                     //
        //                                                                                  //
        //      Gets the sponsor information if it is not empty.                            //
        //                                                                                  //
        //      Note: If the User ID is -1 then it is being checked out by the user.        //
        //      If not then it is being checked by the admin.                               //
        //==================================================================================//
        public static SponsorModel GetSponsorData(SponsorModel spons, int UserId)
        {
            // If the User ID is -1 then it is being checked out by the user. We will then
            // get the current user ID.

            if (UserId == -1)
            {
                UserId = WebSecurity.CurrentUserId;
            }

            try
            {
                using (ITintheDTestTableEntities context = new ITintheDTestTableEntities())
                {
                    // Put everything we find in the database in the var variable. All the
                    // information will be gotten using the User ID.

                    var corporatesponsor = from r in context.ProspectiveCorporateSponsor
                                           where r.SponsorId == UserId
                                           select r;

                    // If the user has some information then edit it.
                    // Otherwise return nothing.

                    if (corporatesponsor.Count() > 0)
                    {
                        spons.AccountStatus = corporatesponsor.FirstOrDefault().Status;
                        spons.CompanyName = corporatesponsor.FirstOrDefault().CompanyName;
                        spons.CompanyAddress = corporatesponsor.FirstOrDefault().CompanyAddress;
                        spons.ContactName = corporatesponsor.FirstOrDefault().ContactName;
                        spons.Title = corporatesponsor.FirstOrDefault().Title;
                        spons.Telephone = corporatesponsor.FirstOrDefault().Telephone;
                        spons.EmailAddress = corporatesponsor.FirstOrDefault().EmailAddress;
                        spons.Reason = corporatesponsor.FirstOrDefault().Reason;
                        spons.ImageUploaded = corporatesponsor.FirstOrDefault().ImageUploaded;
                        spons.SponsorTextField = corporatesponsor.FirstOrDefault().SponsorPageTextField;

                        // Return the modal that is filled with information from the database.

                        return (spons);
                    }
                    else
                    {
                        return (null);
                    }
                }
            }
            catch
            {
                return (null);
            }
        }
Ejemplo n.º 15
0
        public ActionResult SaveSponsor(SponsorModel Model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Invalid Data" }));
            }

            var battle = _videoBattleService.GetById(Model.BattleId); //todo: query picture battles when ready

            if (battle == null)
            {
                return(Json(new { Success = false, Message = "Invalid Battle" }));
            }

            //because somebody wants to be a sponsor, let's first query the sponsorship pass
            var sponsorPass = _sponsorPassService.GetSponsorPassByOrderId(Model.SponsorPassId);

            //the sponsor pass must belong to the person in question && it shouldn't have been used
            if (sponsorPass == null || sponsorPass.CustomerId != _workContext.CurrentCustomer.Id || sponsorPass.Status == PassStatus.Used)
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }

            //lets find the associated order
            var order = _orderService.GetOrderById(sponsorPass.SponsorPassOrderId);

            //there is a possibility that a sponsor is increasing the sponsorship amount. In that case, the new order status will automatically
            //be of same status as that of previous one for the same battle
            //lets find if the sponsor already exist for this battle?
            var existingSponsors = _sponsorService.GetSponsors(order.CustomerId, Model.BattleId, Model.BattleType, null);

            var newSponsorStatus = SponsorshipStatus.Pending;

            //so is the current customer already an sponsor for this battle?
            if (existingSponsors.Any())
            {
                newSponsorStatus = existingSponsors.First().SponsorshipStatus;
            }


            //create the sponsor and set the status to pending or an existing status as determined above. (the status will be marked accepted or rejected or cancelled by battle owner)
            var sponsor = new Sponsor()
            {
                BattleId          = Model.BattleId,
                BattleType        = Model.BattleType,
                SponsorshipAmount = order.OrderTotal,
                CustomerId        = sponsorPass.CustomerId,
                SponsorshipStatus = newSponsorStatus
            };

            //save the sponsor
            _sponsorService.Insert(sponsor);

            //and mark the sponsor pass used by this battle
            _sponsorPassService.MarkSponsorPassUsed(sponsorPass.SponsorPassOrderId, Model.BattleId, Model.BattleType);


            var battleOwner = _customerService.GetCustomerById(battle.ChallengerId);

            var sponsorCustomer = _customerService.GetCustomerById(sponsorPass.CustomerId);

            //send notification to battle owner
            _mobSocialMessageService.SendSponsorAppliedNotificationToBattleOwner(battleOwner, sponsorCustomer, battle,
                                                                                 _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id);

            return(Json(new { Success = true }));
        }
Ejemplo n.º 16
0
        public IHttpActionResult SaveSponsor(SponsorModel Model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { Success = false, Message = "Invalid Data" }));
            }

            var battle = _videoBattleService.GetById(Model.BattleId); //todo: query picture battles when ready

            if (battle == null)
            {
                return(Json(new { Success = false, Message = "Invalid Battle" }));
            }

            var isProductOnlySponsorship = Model.SponsorshipType == SponsorshipType.OnlyProducts;

            var customerId = _workContext.CurrentCustomer.Id;

            SponsorPass sponsorPass = null;
            Order       order       = null;

            if (!isProductOnlySponsorship)
            {
                //because somebody wants to be a sponsor, let's first query the sponsorship pass
                sponsorPass = _sponsorPassService.GetSponsorPassByOrderId(Model.SponsorPassId);

                //the sponsor pass must belong to the person in question && it shouldn't have been used
                if (sponsorPass == null || sponsorPass.CustomerId != customerId || sponsorPass.Status == PassStatus.Used)
                {
                    return(Json(new { Success = false, Message = "Unauthorized" }));
                }
            }

            //lets find the associated order
            order = isProductOnlySponsorship ? null : _orderService.GetOrderById(sponsorPass.SponsorPassOrderId);

            //there is a possibility that a sponsor is increasing the sponsorship amount. In that case, the new order status will automatically
            //be of same status as that of previous one for the same battle
            //lets find if the sponsor already exist for this battle?
            var existingSponsors = _sponsorService.GetSponsors(customerId, Model.BattleId, Model.BattleType, null);

            var newSponsorStatus = SponsorshipStatus.Pending;

            //so is the current customer already an sponsor for this battle?
            if (existingSponsors.Any())
            {
                newSponsorStatus = existingSponsors.First().SponsorshipStatus;
            }


            //create the sponsor and set the status to pending or an existing status as determined above. (the status will be marked accepted or rejected or cancelled by battle owner)
            var sponsor = new Sponsor()
            {
                BattleId          = Model.BattleId,
                BattleType        = Model.BattleType,
                SponsorshipAmount = isProductOnlySponsorship ? 0 : order.OrderTotal,
                CustomerId        = customerId,
                SponsorshipStatus = newSponsorStatus,
                DateCreated       = DateTime.UtcNow,
                DateUpdated       = DateTime.UtcNow
            };

            //save the sponsor
            _sponsorService.Insert(sponsor);

            if (!isProductOnlySponsorship)
            {
                //if it's already approved sponsor, it's better to immediately capture the order
                if (newSponsorStatus == SponsorshipStatus.Accepted)
                {
                    var captureResult = _paymentProcessingService.CapturePayment(order);
                    if (!captureResult.Success)
                    {
                        return(Json(new { Success = false, Message = "Failed to capture order" }));
                    }
                    order.PaymentStatus            = captureResult.NewPaymentStatus;
                    order.CaptureTransactionId     = captureResult.CaptureTransactionId;
                    order.CaptureTransactionResult = captureResult.CaptureTransactionResult;
                    _orderService.UpdateOrder(order);
                }
                //and mark the sponsor pass used by this battle
                _sponsorPassService.MarkSponsorPassUsed(sponsorPass.SponsorPassOrderId, Model.BattleId, Model.BattleType);
            }
            else
            {
                //save the prizes only sponsorship prizes
                SaveSponsorProductPrizes(Model.Prizes);
            }


            var battleOwner = _customerService.GetCustomerById(battle.ChallengerId);

            var sponsorCustomer = _customerService.GetCustomerById(customerId);

            //send notification to battle owner
            _mobSocialMessageService.SendSponsorAppliedNotificationToBattleOwner(battleOwner, sponsorCustomer, battle,
                                                                                 _workContext.WorkingLanguage.Id, _storeContext.CurrentStore.Id);

            return(Json(new { Success = true }));
        }
Ejemplo n.º 17
0
        //==================================================================================//
        //      Store Sponsor information                                                   //
        //                                                                                  //
        //      Register the sponsor information if it is empty. Otherwise edit it.         //
        //                                                                                  //
        //      Note: If the edit is true then the account is being edited.                 //
        //      Otherwise it is being registered.                                           //
        //==================================================================================//
        public static bool StoreSponsorData(SponsorModel sponsor, ref bool edit)
        {
            int UserId = WebSecurity.GetUserId(sponsor.EmailAddress);

            edit = false;

            try
            {
                ProspectiveCorporateSponsor CurrentSponsor;

                using (ITintheDTestTableEntities context = new ITintheDTestTableEntities())
                {
                    // Put everything we find in the database in the var variable. All the
                    // information will be gotten using the User ID.

                    var SponsorData = from r in context.ProspectiveCorporateSponsor
                                      where r.SponsorId == UserId
                                      select r;

                    // If the user has some information then edit it.
                    // Otherwise register the account.

                    if (SponsorData.Count() > 0 && UserId > 0)
                    {
                        CurrentSponsor = SponsorData.FirstOrDefault();
                        CurrentSponsor.Status = sponsor.AccountStatus;
                        CurrentSponsor.CompanyAddress = sponsor.CompanyAddress;
                        CurrentSponsor.CompanyName = sponsor.CompanyName;
                        CurrentSponsor.ContactName = sponsor.ContactName;
                        CurrentSponsor.EmailAddress = sponsor.EmailAddress;
                        CurrentSponsor.Title = sponsor.Title;
                        CurrentSponsor.Telephone = sponsor.Telephone;
                        CurrentSponsor.Reason = sponsor.Reason;
                        CurrentSponsor.SponsorPageTextField = sponsor.SponsorTextField;
                        CurrentSponsor.SponsorId = UserId;

                        // Store the avatar if it is supplied.

                        if (sponsor.ImageFile != null)
                        {
                            UserImage image = new UserImage();

                            using (MemoryStream ms = new MemoryStream())
                            {
                                sponsor.ImageFile.InputStream.CopyTo(ms);

                                image.FileContent = ms.ToArray();
                                image.FileName = Path.GetFileName(sponsor.ImageFile.FileName);
                                image.ContentType = sponsor.ImageFile.ContentType;
                                image.ContentLength = sponsor.ImageFile.ContentLength;

                                DatabaseHelper.UploadImage(image, CurrentSponsor.SponsorId);

                                CurrentSponsor.ImageUploaded = "Yes";
                                sponsor.ImageUploaded = "Yes";
                            }
                        }

                        edit = true;
                    }
                    else
                    {
                        CurrentSponsor = new ProspectiveCorporateSponsor();

                        CurrentSponsor.Status = sponsor.AccountStatus;
                        CurrentSponsor.CompanyAddress = sponsor.CompanyAddress;
                        CurrentSponsor.CompanyName = sponsor.CompanyName;
                        CurrentSponsor.ContactName = sponsor.ContactName;
                        CurrentSponsor.EmailAddress = sponsor.EmailAddress;
                        CurrentSponsor.Title = sponsor.Title;
                        CurrentSponsor.Telephone = sponsor.Telephone;
                        CurrentSponsor.Reason = sponsor.Reason;
                        CurrentSponsor.SponsorPageTextField = sponsor.SponsorTextField;

                        context.AddToProspectiveCorporateSponsor(CurrentSponsor);
                    }

                    try
                    {
                        // If the account is edited then save changes. Otherwise register the account.

                        if (edit == false)
                        {
                            WebSecurity.CreateUserAndAccount(sponsor.EmailAddress, sponsor.Password);

                            // User is automatically logged in here.

                            WebSecurity.Login(sponsor.EmailAddress, sponsor.Password);

                            DatabaseHelper.AddUserToRole(sponsor.EmailAddress, "Sponsor");

                            CurrentSponsor.SponsorId = WebSecurity.GetUserId(sponsor.EmailAddress);

                            // Store the avatar if it is supplied.

                            if (sponsor.ImageFile != null)
                            {
                                UserImage image = new UserImage();

                                using (MemoryStream ms = new MemoryStream())
                                {
                                    sponsor.ImageFile.InputStream.CopyTo(ms);

                                    image.FileContent = ms.ToArray();
                                    image.FileName = Path.GetFileName(sponsor.ImageFile.FileName);
                                    image.ContentType = sponsor.ImageFile.ContentType;
                                    image.ContentLength = sponsor.ImageFile.ContentLength;

                                    DatabaseHelper.UploadImage(image, CurrentSponsor.SponsorId);

                                    CurrentSponsor.ImageUploaded = "Yes";
                                    sponsor.ImageUploaded = "Yes";
                                }
                            }

                            else
                            {
                                CurrentSponsor.ImageUploaded = "No";
                                sponsor.ImageUploaded = "No";
                            }
                        }

                        context.SaveChanges();

                        return true;
                    }

                    catch (Exception e)
                    {
                        string errorMessage = e.Message;

                        return false;
                    }
                }
            }

            catch (Exception ex)
            {
                string exMessage = ex.Message;

                return false;
            }
        }