Exemplo n.º 1
0
        public ActionResult EditPerson(FormCollection fc, int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tOsoby person = service.GetPersonData(id.Value);

            try
            {
                if (TryUpdateModel(person, "") && TryUpdateModel(person.tAdresy, "tAdresy"))
                {
                    if (CheckPasswords(fc, service.GetClient(person.IDKlienta)))
                    {
                        if (ModelState.IsValid)
                        {
                            service.ChangePersonData(person);
                            if (ChangePassword(fc["OldPassword"], fc["NewPassword"], person.IDKlienta))
                            {
                                service.Save();
                                ViewBag.Message = "Data saved successfully.";
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                HandleEditionException(ex);
            }

            CreateAddressCountryList(fc);
            return(View(person));
        }
Exemplo n.º 2
0
 public void UpdatePerson(tOsoby person, ITravelAgencyService service)
 {
     person.NIP      = NIP.Text;
     person.Imie     = FirstName.Text;
     person.Nazwisko = Surname.Text;
     Address.UpdateAddress(person.tAdresy, service);
 }
Exemplo n.º 3
0
        public ActionResult Edit()
        {
            int?userId = service.GetClientId(User.Identity.Name);

            if (userId.HasValue)
            {
                CreateAddressCountryList(null);
                tFirmy firm = service.GetFirmData(userId.Value);
                if (firm != null)
                {
                    return(View("EditFirm", firm));
                }
                else
                {
                    tOsoby person = service.GetPersonData(userId.Value);
                    if (person == null)
                    {
                        return(RedirectToAction("Login"));
                    }
                    else
                    {
                        return(View("EditPerson", person));
                    }
                }
            }
            return(View());
        }
Exemplo n.º 4
0
        public void CreatePerson(tOsoby person, tAdresy address, string email)
        {
            var client = GetNonNullClientId(email);

            person.IDKlienta = client.IDKlienta;
            person.tKlient   = client;
            person.tAdresy   = address;
            context.tOsoby.Add(person);
        }
Exemplo n.º 5
0
 public void AssignData(tOsoby person)
 {
     ClientId.Value = person.tKlient.IDKlienta.ToString();
     NIP.Text       = person.NIP;
     FirstName.Text = person.Imie;
     Surname.Text   = person.Nazwisko;
     Address.AssignData(person.tAdresy);
     LoginData.AssignData(person.tKlient);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Returns person data prior to the modification.
        /// </summary>
        /// <returns>the person data object</returns>
        private tOsoby GetPersonData()
        {
            int?userId = service.GetClientId(User.Identity.Name);

            if (userId.HasValue)
            {
                tOsoby person = service.GetPersonData(userId.Value);
                return(person);
            }
            return(null);
        }
Exemplo n.º 7
0
        private void AssignData()
        {
            tOsoby person = GetPersonData();

            if (person != null)
            {
                IsPerson = true;
                PersonData.AssignData(person);
            }
            else
            {
                tFirmy firm = GetFirmData();
                if (firm != null)
                {
                    IsFirm = true;
                    FirmData.AssignData(firm);
                }
            }
        }
Exemplo n.º 8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         AssignData();
     }
     else
     {
         tOsoby person = GetPersonData();
         if (person != null)
         {
             IsPerson = true;
         }
         else
         {
             IsFirm = GetFirmData() != null;
         }
     }
     PersonData.Visible = IsPerson;
     FirmData.Visible   = !IsPerson;
 }
Exemplo n.º 9
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);
                    }
                }
            }
        }
Exemplo n.º 10
0
 public void CreatePerson(tOsoby person, tAdresy address, string email)
 {
     unitOfWork.CreatePerson(person, address, email);
 }
Exemplo n.º 11
0
 public void ChangePersonData(tOsoby person)
 {
     unitOfWork.ChangePersonData(person);
 }
Exemplo n.º 12
0
 public void ChangePersonData(tOsoby person)
 {
     context.tOsoby.Attach(person);
     context.Entry(person).State         = EntityState.Modified;
     context.Entry(person.tAdresy).State = EntityState.Modified;
 }