Ejemplo n.º 1
0
 protected void CreateUser_Click(object sender, EventArgs e)
 {
     if (IsValid)
     {
         try
         {
             TravelAgencyService service = new TravelAgencyService();
             try
             {
                 if (FirmPanel.Visible)
                 {
                     CreateUser(FirmData.EmailString, FirmData.PasswordString, service, () =>
                     {
                         service.CreateFirm(FirmData.Firm, FirmData.GetAddressEntity(service), FirmData.EmailString);
                     });
                 }
                 else if (PersonPanel.Visible)
                 {
                     CreateUser(PersonData.EmailString, PersonData.PasswordString, service, () =>
                     {
                         service.CreatePerson(PersonData.Person, PersonData.GetAddressEntity(service), PersonData.EmailString);
                     });
                 }
             }
             finally
             {
                 service.Dispose();
             }
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("", ex.Message);
         }
     }
 }
Ejemplo n.º 2
0
        private void CreateUser(String email, String password, TravelAgencyService service, Action createUser)
        {
            List <String> errorList = new List <string>(1);
            bool          isSuccess = false;

            // Attempt to register the user
            if (WebDataHelper.CreateAccount(email, password, errorList))
            {
                try
                {
                    createUser();
                    service.Save();
                    WebSecurity.Login(email, password);
                    isSuccess = true;
                }
                catch (Exception ex)
                {
                    HandleRegistrationError(email, ex);
                }
            }
            else
            {
                ModelState.AddModelError("", "E-mail is already in use.");
            }
            // Warning: Redirect to URL throws special exception which must not be handled.
            // Whne it is handled in above try then the newly created account is deleted.
            if (isSuccess)
            {
                RedirectHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
        }
Ejemplo n.º 3
0
 public static int?GetUserId(TravelAgencyService service, IPrincipal user)
 {
     if (user.Identity.IsAuthenticated)
     {
         return(service.GetClientId(user.Identity.Name));
     }
     return(null);
 }
Ejemplo n.º 4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (User.Identity.IsAuthenticated)
     {
         TravelAgencyService service = new TravelAgencyService();
         using (service.ToDisposable())
         {
             offerIdToReservedMap = service.GetOfferIdToReservedMap(service.GetClientId(User.Identity.Name));
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns Client ID for the logged user.
 /// </summary>
 /// <param name="user">the logged user</param>
 /// <returns>the Client ID or null when it is not found</returns>
 public static int?GetLoggerClientID(IPrincipal user)
 {
     if (user.Identity.IsAuthenticated)
     {
         TravelAgencyService service = new TravelAgencyService();
         using (service.ToDisposable())
         {
             int?userId = service.GetClientId(user.Identity.Name);
             return(userId);
         }
     }
     return(null);
 }
Ejemplo n.º 6
0
        protected void btnOfferHistory_Click(object sender, EventArgs e)
        {
            int aid;

            if (int.TryParse(Request.QueryString["aid"], out aid))
            {
                TravelAgencyService service = new TravelAgencyService();
                using (service.ToDisposable())
                {
                    int?offerId = service.GetOfferHistoryIdByAttractionId(aid);
                    if (offerId.HasValue)
                    {
                        Response.Redirect(String.Format("/Logged/OfferHistoryDetails?oid={0}", offerId.Value));
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static void AddUserToRole(String userName)
        {
            var service = new TravelAgencyService();
            int?userid  = service.GetClientId(userName);

            if (userid != null)
            {
                tOsoby person = service.GetPersonData(userid.Value);
                if (person != null)
                {
                    String roleName = person.bPracownik ? ADMIN_ROLE : CLIENT_ROLE;
                    if (!Roles.IsUserInRole(userName, roleName))
                    {
                        if (Roles.GetAllRoles().Where(r => r == roleName).FirstOrDefault() == null)
                        {
                            Roles.CreateRole(roleName);
                        }
                        Roles.AddUserToRole(userName, roleName);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 public static void ClassInitialize(TestContext context)
 {
     service = new TravelAgencyService();
 }