Exemple #1
0
        private static void AddModel(object param)
        {
            ViewPerson model = new ViewPerson();
            Dictionary <string, string> input = Menu.GetInput("Please enter the following information", "Name", "Age");

            model.Name = input["Name"];
            model.Age  = input["Age"];
            new ExampleController().SavePerson(model);
        }
Exemple #2
0
        private static void UpdateModel(object param)
        {
            ViewPerson model = (ViewPerson)param;
            string     name  = "Name (" + model.Name + ")";
            string     age   = "Age (" + model.Age + ")";
            Dictionary <string, string> input = Menu.GetInput("Please enter the following information", name, age);

            model.Name = input[name];
            model.Age  = input[age];
            new ExampleController().SavePerson(model);
        }
Exemple #3
0
        // GET: api/Person/5
        public ViewPerson GetPerson(int id)
        {
            ViewPerson person = db.Person.Find(id);

            if (person == null)
            {
                Exception ex = new Exception("Persona no encontrada");
                throw ex;
            }

            return(person);
        }
Exemple #4
0
        public ViewPerson PostPerson([FromBody] Person person)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("No valido");
            }
            db.Person.Add(person);
            db.SaveChanges();
            ViewPerson viewPerson = person;

            return(viewPerson);
        }
Exemple #5
0
        public static void UIForConsoleApp()
        {
            ConsoleKeyInfo   info;
            PersonRepository personRepository = new PersonRepository();

            do
            {
                Console.Clear();
                Console.WriteLine("Database coding - CRUD");
                Console.WriteLine("Press <ESC> to Exit");
                Console.WriteLine("C) Create");
                Console.WriteLine("R) Read All");
                Console.WriteLine("U) Update");
                Console.WriteLine("D) Delete");
                Console.WriteLine("-------------");
                Console.WriteLine("G) Get by ID");

                info = Console.ReadKey();

                switch (info.Key)
                {
                case ConsoleKey.C:
                    ViewPerson.AddPerson();
                    break;

                case ConsoleKey.R:
                    ViewPerson.PrintToScreen(personRepository.Get());
                    Console.WriteLine("Press <Enter> to continue ...");
                    Console.ReadLine();
                    break;

                case ConsoleKey.U:
                    Person updatePerson = personRepository.GetPersonById(4);
                    updatePerson.Name = "Patrik";
                    updatePerson.Age  = 34;
                    personRepository.Update(1, updatePerson);
                    break;

                case ConsoleKey.D:
                    personRepository.Delete(5);
                    break;

                case ConsoleKey.G:
                    Console.Write("\nType person <id>, who´s information will show: ");
                    int id = int.Parse(Console.ReadLine());
                    ViewPerson.PrintToScreen(personRepository.GetPersonByIdAndPhones(id));
                    Console.WriteLine("Press <Enter> to continue ...");
                    Console.ReadLine();
                    break;
                }
            } while (info.Key != ConsoleKey.Escape);
        }
        //通过电影ID查找导演
        public List <ViewPerson> GetDirectorByMovie(string MovieID)
        {
            var persons    = context.Director.ToLookup(d => d.m_id)[MovieID].ToList();
            var returnList = new List <ViewPerson> {
            };

            foreach (var temp in persons)
            {
                Person tempperson = context.Person.FirstOrDefault(p => p.person_id == temp.person_id);
                var    add        = new ViewPerson
                {
                    PersonID   = tempperson.person_id,
                    PersonArea = tempperson.person_area,
                    PersonName = tempperson.person_name
                };
                returnList.Add(add);
            }
            return(returnList);
        }
Exemple #7
0
 public void CreatePerson(ViewPerson newPerson)
 {
     try
     {
         var subServicesPerson = new BussinessPerson(newPerson);
         this.ServiceData.CreatePerson(subServicesPerson.ValidationNewPerson());
     }
     catch (ValidationException ex)
     {
         throw;
     }
     catch (PersonException ex)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Exemple #8
0
        public static void UIForConsoleApp()
        {
            ConsoleKeyInfo   info;
            PersonRepository personRepository = new PersonRepository();

            do
            {
                Console.Clear();
                Console.WriteLine("Database coding - CRUD");
                Console.WriteLine("Press <ESC> to Exit");
                Console.WriteLine("C) Create");
                Console.WriteLine("R) Read All");
                Console.WriteLine("U) Update");
                Console.WriteLine("D) Delete");
                Console.WriteLine("-------------");
                Console.WriteLine("G) Get by ID");

                info = Console.ReadKey();

                switch (info.Key)
                {
                case ConsoleKey.C:
                    ViewPerson.AddPerson();
                    //var person = new Person("Jorska", 25);
                    //personRepository.Create(person);
                    break;

                case ConsoleKey.R:
                    ViewPerson.PrintToScreen(personRepository.Get());
                    Console.WriteLine("Press <Enter> to continue ...");
                    Console.ReadLine();
                    break;

                case ConsoleKey.U:
                    Person updatePerson = personRepository.GetPersonById(10);
                    updatePerson.Name = "James Bond";
                    updatePerson.Age  = 55;
                    personRepository.Update(1, updatePerson);
                    break;

                case ConsoleKey.D:
                    personRepository.Delete(5);
                    break;

                case ConsoleKey.G:
                    Console.Write("\nSyötä henkilön <id>, jonka tiedot näytetään: ");
                    int id = int.Parse(Console.ReadLine());
                    ViewPerson.PrintToScreen(personRepository.GetPersonByIdAndPhones(id));
                    Console.WriteLine("Press <Enter> to continue ...");
                    Console.ReadLine();
                    break;

                case ConsoleKey.Escape:
                    Console.WriteLine("\nProgram end after 3 sec!");
                    for (int i = 0; i < 3; i++)
                    {
                        Console.Write(".");
                        System.Threading.Thread.Sleep(1000);
                    }
                    break;

                default:
                    Console.WriteLine("\nWrong KEY - try again!");
                    System.Threading.Thread.Sleep(2000);
                    break;
                }
            } while (info.Key != ConsoleKey.Escape);
        }
Exemple #9
0
        public static void UiForConsoleApp()
        {
            ConsoleKeyInfo info;
            var            personRepository = new PersonRepository();

            do
            {
                Console.Clear();
                Console.WriteLine("Database coding - CRUD");
                Console.WriteLine("Press <ESC> to Exit");
                Console.WriteLine("C) Create");
                Console.WriteLine("R) Read All");
                Console.WriteLine("U) Update");
                Console.WriteLine("D) Delete");
                Console.WriteLine("G) Get by ID");
                Console.WriteLine("-------------");

                info = Console.ReadKey();

                switch (info.Key)
                {
                case ConsoleKey.C:
                    ViewPerson.AddPerson();
                    //var person = new Person("Kipe", 22);
                    //personRepository.Create(person);
                    break;

                case ConsoleKey.R:
                    ViewPerson.PrintToScreen(personRepository.Read());
                    Console.WriteLine("Press <Enter> to continue ...");
                    Console.ReadLine();
                    break;

                case ConsoleKey.U:
                    var updatePerson = personRepository.GetPersonById(10);
                    updatePerson.Name = "Jaska Jokunen";
                    updatePerson.Age  = 45;
                    personRepository.Update(updatePerson, 1);
                    break;

                case ConsoleKey.D:
                    personRepository.Delete(5);
                    break;

                case ConsoleKey.G:
                    Console.Write("\nSyötä henkilön <id>, jonka tiedot näytetään: ");
                    var id = int.Parse(Console.ReadLine());
                    ViewPerson.PrintToScreen(personRepository.GetPersonByIdAndPhones(id));
                    Console.WriteLine("Press <Enter> to continue ...");
                    Console.ReadLine();
                    break;

                case ConsoleKey.Escape:
                    Console.WriteLine("\nProgram ends after 2 seconds!");
                    for (var i = 0; i < 3; i++)
                    {
                        Console.Write(".");
                        System.Threading.Thread.Sleep(1000);
                    }
                    break;

                case ConsoleKey.A:
                    break;

                case ConsoleKey.Add:
                    break;

                case ConsoleKey.Applications:
                    break;

                case ConsoleKey.Attention:
                    break;

                case ConsoleKey.B:
                    break;

                case ConsoleKey.Backspace:
                    break;

                case ConsoleKey.BrowserBack:
                    break;

                case ConsoleKey.BrowserFavorites:
                    break;

                case ConsoleKey.BrowserForward:
                    break;

                case ConsoleKey.BrowserHome:
                    break;

                case ConsoleKey.BrowserRefresh:
                    break;

                case ConsoleKey.BrowserSearch:
                    break;

                case ConsoleKey.BrowserStop:
                    break;

                case ConsoleKey.Clear:
                    break;

                case ConsoleKey.CrSel:
                    break;

                case ConsoleKey.D0:
                    break;

                case ConsoleKey.D1:
                    break;

                case ConsoleKey.D2:
                    break;

                case ConsoleKey.D3:
                    break;

                case ConsoleKey.D4:
                    break;

                case ConsoleKey.D5:
                    break;

                case ConsoleKey.D6:
                    break;

                case ConsoleKey.D7:
                    break;

                case ConsoleKey.D8:
                    break;

                case ConsoleKey.D9:
                    break;

                case ConsoleKey.Decimal:
                    break;

                case ConsoleKey.Delete:
                    break;

                case ConsoleKey.Divide:
                    break;

                case ConsoleKey.DownArrow:
                    break;

                case ConsoleKey.E:
                    break;

                case ConsoleKey.End:
                    break;

                case ConsoleKey.Enter:
                    break;

                case ConsoleKey.EraseEndOfFile:
                    break;

                case ConsoleKey.Execute:
                    break;

                case ConsoleKey.ExSel:
                    break;

                case ConsoleKey.F:
                    break;

                case ConsoleKey.F1:
                    break;

                case ConsoleKey.F10:
                    break;

                case ConsoleKey.F11:
                    break;

                case ConsoleKey.F12:
                    break;

                case ConsoleKey.F13:
                    break;

                case ConsoleKey.F14:
                    break;

                case ConsoleKey.F15:
                    break;

                case ConsoleKey.F16:
                    break;

                case ConsoleKey.F17:
                    break;

                case ConsoleKey.F18:
                    break;

                case ConsoleKey.F19:
                    break;

                case ConsoleKey.F2:
                    break;

                case ConsoleKey.F20:
                    break;

                case ConsoleKey.F21:
                    break;

                case ConsoleKey.F22:
                    break;

                case ConsoleKey.F23:
                    break;

                case ConsoleKey.F24:
                    break;

                case ConsoleKey.F3:
                    break;

                case ConsoleKey.F4:
                    break;

                case ConsoleKey.F5:
                    break;

                case ConsoleKey.F6:
                    break;

                case ConsoleKey.F7:
                    break;

                case ConsoleKey.F8:
                    break;

                case ConsoleKey.F9:
                    break;

                case ConsoleKey.H:
                    break;

                case ConsoleKey.Help:
                    break;

                case ConsoleKey.Home:
                    break;

                case ConsoleKey.I:
                    break;

                case ConsoleKey.Insert:
                    break;

                case ConsoleKey.J:
                    break;

                case ConsoleKey.K:
                    break;

                case ConsoleKey.L:
                    break;

                case ConsoleKey.LaunchApp1:
                    break;

                case ConsoleKey.LaunchApp2:
                    break;

                case ConsoleKey.LaunchMail:
                    break;

                case ConsoleKey.LaunchMediaSelect:
                    break;

                case ConsoleKey.LeftArrow:
                    break;

                case ConsoleKey.LeftWindows:
                    break;

                case ConsoleKey.M:
                    break;

                case ConsoleKey.MediaNext:
                    break;

                case ConsoleKey.MediaPlay:
                    break;

                case ConsoleKey.MediaPrevious:
                    break;

                case ConsoleKey.MediaStop:
                    break;

                case ConsoleKey.Multiply:
                    break;

                case ConsoleKey.N:
                    break;

                case ConsoleKey.NoName:
                    break;

                case ConsoleKey.NumPad0:
                    break;

                case ConsoleKey.NumPad1:
                    break;

                case ConsoleKey.NumPad2:
                    break;

                case ConsoleKey.NumPad3:
                    break;

                case ConsoleKey.NumPad4:
                    break;

                case ConsoleKey.NumPad5:
                    break;

                case ConsoleKey.NumPad6:
                    break;

                case ConsoleKey.NumPad7:
                    break;

                case ConsoleKey.NumPad8:
                    break;

                case ConsoleKey.NumPad9:
                    break;

                case ConsoleKey.O:
                    break;

                case ConsoleKey.Oem1:
                    break;

                case ConsoleKey.Oem102:
                    break;

                case ConsoleKey.Oem2:
                    break;

                case ConsoleKey.Oem3:
                    break;

                case ConsoleKey.Oem4:
                    break;

                case ConsoleKey.Oem5:
                    break;

                case ConsoleKey.Oem6:
                    break;

                case ConsoleKey.Oem7:
                    break;

                case ConsoleKey.Oem8:
                    break;

                case ConsoleKey.OemClear:
                    break;

                case ConsoleKey.OemComma:
                    break;

                case ConsoleKey.OemMinus:
                    break;

                case ConsoleKey.OemPeriod:
                    break;

                case ConsoleKey.OemPlus:
                    break;

                case ConsoleKey.P:
                    break;

                case ConsoleKey.Pa1:
                    break;

                case ConsoleKey.Packet:
                    break;

                case ConsoleKey.PageDown:
                    break;

                case ConsoleKey.PageUp:
                    break;

                case ConsoleKey.Pause:
                    break;

                case ConsoleKey.Play:
                    break;

                case ConsoleKey.Print:
                    break;

                case ConsoleKey.PrintScreen:
                    break;

                case ConsoleKey.Process:
                    break;

                case ConsoleKey.Q:
                    break;

                case ConsoleKey.RightArrow:
                    break;

                case ConsoleKey.RightWindows:
                    break;

                case ConsoleKey.S:
                    break;

                case ConsoleKey.Select:
                    break;

                case ConsoleKey.Separator:
                    break;

                case ConsoleKey.Sleep:
                    break;

                case ConsoleKey.Spacebar:
                    break;

                case ConsoleKey.Subtract:
                    break;

                case ConsoleKey.T:
                    break;

                case ConsoleKey.Tab:
                    break;

                case ConsoleKey.UpArrow:
                    break;

                case ConsoleKey.V:
                    break;

                case ConsoleKey.VolumeDown:
                    break;

                case ConsoleKey.VolumeMute:
                    break;

                case ConsoleKey.VolumeUp:
                    break;

                case ConsoleKey.W:
                    break;

                case ConsoleKey.X:
                    break;

                case ConsoleKey.Y:
                    break;

                case ConsoleKey.Z:
                    break;

                case ConsoleKey.Zoom:
                    break;

                default:
                    Console.WriteLine("\nWrong KEY - try again!");
                    System.Threading.Thread.Sleep(1000);
                    break;
                }
            } while (info.Key != ConsoleKey.Escape);
        }
Exemple #10
0
        //ati login
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            try
            {
                UnitOfWork unitOfWork  = new UnitOfWork();
                var        userManager = context.OwinContext.GetUserManager <ApplicationUserManager>();

                ApplicationUser user = await userManager.FindAsync(context.UserName, context.Password);



                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
                var roles = userManager.GetRoles(user.Id).First();


                var scope      = context.Scope.ToList();
                var customerId = Convert.ToInt32(context.Scope[0]);



                ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                    OAuthDefaults.AuthenticationType);

                ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager,
                                                                                      CookieAuthenticationDefaults.AuthenticationType);

                oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, context.UserName));
                if (roles == "Company")
                {
                    oAuthIdentity.AddClaim(new Claim(ClaimTypes.Role, "Company"));
                }
                else if (roles == "User")
                {
                    oAuthIdentity.AddClaim(new Claim(ClaimTypes.Role, "nuser"));
                }
                else
                {
                    oAuthIdentity.AddClaim(new Claim(ClaimTypes.Role, "user"));
                }


                oAuthIdentity.AddClaim(new Claim("sub", context.UserName));
                oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, "Vahid"));

                AuthenticationProperties properties = CreateProperties(user.UserName, (context.ClientId == null) ? string.Empty : context.ClientId);

                if (roles == "Company")
                {
                    var company = await unitOfWork.CompanyRepository.GetViewCompanyByEmail(context.UserName);

                    if (company != null)
                    {
                        properties.Dictionary.Add("Name", company.Name);
                        properties.Dictionary.Add("UserId", company.Id.ToString());
                        properties.Dictionary.Add("Image", string.IsNullOrEmpty(company.ImageUrl) ?"": company.ImageUrl.ToString());
                        properties.Dictionary.Add("Role", "Company");
                        //   properties.Dictionary.Add("EmployeeId", employee.Id.ToString());
                    }
                }
                else
                {
                    ViewPerson person = await unitOfWork.PersonRepository.GetViewPersonByUserId(user.Id);

                    if (person != null)
                    {
                        properties.Dictionary.Add("Name", person.Name);
                        properties.Dictionary.Add("UserId", person.Id.ToString());
                        properties.Dictionary.Add("Image", person.ImageUrl.ToString());
                        properties.Dictionary.Add("Role", roles != "User"? "Person":"User");
                        //   properties.Dictionary.Add("EmployeeId", employee.Id.ToString());
                    }
                }


                AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
                context.Validated(ticket);
                context.Request.Context.Authentication.SignIn(cookiesIdentity);
            }
            catch (Exception ex)
            {
                int i = 0;
            }
        }
Exemple #11
0
        public static void UIForConsoleApp()
        {
            ConsoleKeyInfo   info;
            PersonRepository personRepository = new PersonRepository();

            do
            {
                Console.Clear();
                Console.WriteLine("Database coding - CRUD");
                Console.WriteLine("Press <ESC> to Exit");
                Console.WriteLine("C) Create");
                Console.WriteLine("R) Read All");
                Console.WriteLine("U) Update");
                Console.WriteLine("D) Delete");
                Console.WriteLine("-------------");
                Console.WriteLine("G) Get by ID");
                Console.WriteLine("A) Update Phone");

                info = Console.ReadKey();

                switch (info.Key)
                {
                case ConsoleKey.C:
                    ViewPerson.AddPerson();
                    //var person = new Person("Masa", 25);
                    //personRepository.Create(person);
                    break;

                case ConsoleKey.R:
                    ViewPerson.PrintToScreen(personRepository.Get());
                    Console.WriteLine("Press <Enter> to continue ...");
                    Console.ReadLine();
                    break;

                case ConsoleKey.U:
                    Person updatePerson = personRepository.GetPersonById(10);
                    updatePerson.Name = "Jouni";
                    updatePerson.Age  = 50;
                    personRepository.Update(1, updatePerson);
                    break;

                case ConsoleKey.D:
                    personRepository.Delete(5);
                    break;

                case ConsoleKey.G:
                    Console.Write("\nSyötä henkilön <id>, jonka tiedot näytetään: ");
                    int id = int.Parse(Console.ReadLine());
                    ViewPerson.PrintToScreen(personRepository.GetPersonByIdAndPhones(id));
                    Console.WriteLine("Press <Enter> to continue ...");
                    Console.ReadLine();
                    break;

                case ConsoleKey.A:
                    Console.Write("\nSyötä henkilön <id>, jonka tiedot näytetään: ");
                    id = int.Parse(Console.ReadLine());
                    Person updatePersonAndPhone = personRepository.GetPersonByIdAndPhones(id);
                    ViewPerson.PrintToScreen(personRepository.GetPersonByIdAndPhones(id));
                    Console.Write("Valitse <Id>, jonka haluat muuttaa: ");
                    int phnId = int.Parse(Console.ReadLine());
                    Console.Write("Syötä uusi numero: ");
                    string newNumber = Console.ReadLine();
                    foreach (var phn in updatePersonAndPhone.Phone)
                    {
                        if (phn.Id == phnId)
                        {
                            phn.Number = newNumber;
                        }
                    }
                    personRepository.Update(10, updatePersonAndPhone);
                    break;

                case ConsoleKey.Escape:
                    Console.WriteLine("\nProgram end after 3 sec!");
                    for (int i = 0; i < 3; i++)
                    {
                        Console.Write(".");
                        System.Threading.Thread.Sleep(1000);
                    }
                    break;

                default:
                    Console.WriteLine("\nWrong KEY - try again!");
                    System.Threading.Thread.Sleep(2000);
                    break;
                }
            } while (info.Key != ConsoleKey.Escape);
        }
Exemple #12
0
 public BussinessPerson(ViewPerson newPerson)
 {
     this.Person = newPerson;
 }