public void Save(TempPerson obj)
 {
     if (obj.Id == 0)
         context.Entry(obj).State = System.Data.Entity.EntityState.Added;
     else
         context.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }
 public void Save(TempPerson obj)
 {
     if (obj.Id == 0)
     {
         context.Entry(obj).State = System.Data.Entity.EntityState.Added;
     }
     else
     {
         context.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     }
     context.SaveChanges();
 }
        public async override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            currentPerson = parameter == null ? new Person()
            {
                Id = Guid.NewGuid().ToString()
            } : parameter as Person;

            var temp = new PersonProxy(currentPerson)
            {
                Name      = currentPerson.Name,
                LastName  = currentPerson.LastName,
                Validator = i =>
                {
                    var u = i as PersonProxy;
                    if (string.IsNullOrEmpty(u.Name))
                    {
                        u.Properties[nameof(u.Name)].Errors.Add("First name is required");
                    }
                    else if (u.Name.Length < 3)
                    {
                        u.Properties[nameof(u.Name)].Errors.Add("First name is less then 3 symbols");
                    }
                    if (string.IsNullOrEmpty(u.LastName))
                    {
                        u.Properties[nameof(u.LastName)].Errors.Add("Last name is required");
                    }
                    if (string.IsNullOrEmpty(u.Email))
                    {
                        u.Properties[nameof(u.Email)].Errors.Add("Email is required.");
                    }
                    else if (!new System.ComponentModel.DataAnnotations.EmailAddressAttribute().IsValid(u.Email))
                    {
                        u.Properties[nameof(u.Email)].Errors.Add("A valid Email is required.");
                    }
                },
            };

            TempPerson = temp;
            TempPerson.Validate();

            if (parameter == null)
            {
                currentState = States.Add;
                Title        = "Adding new person";
            }
            else if (parameter != null)
            {
                currentState = States.Edit;
                Title        = $"Editting {TempPerson.FullName}";
            }
            await Task.CompletedTask;
        }
        public void DoesDijkstraSendToPrefRoom()
        {
            //arrange
            TempPerson  person      = new TempPerson();
            Dijkstra    dijkstra    = new Dijkstra();
            RoomFactory roomFactory = new RoomFactory();

            roomFactory.GenerateEntity();
            dijkstra.CreateGraph(roomFactory.coordinates);
            IRoom start = roomFactory.coordinates[0, 1];
            IRoom end   = roomFactory.coordinates[1, 1];

            //act
            List <IRoom> path = dijkstra.Run(start, end, person);

            //assert
            Assert.AreEqual(end, path.Last());
        }
        private void SetTempPerson(object person)
        {
            currentPerson = person == null ? new Person()
            {
                Id = Guid.NewGuid().ToString()
            } : person as Person;

            var temp = new PersonProxy(currentPerson)
            {
                Name        = currentPerson.Name,
                LastName    = currentPerson.LastName,
                Email       = currentPerson.Email,
                DateOfBirth = currentPerson.DateOfBirth,
                Validator   = i =>
                {
                    var u = i as PersonProxy;
                    if (string.IsNullOrEmpty(u.Name))
                    {
                        u.Properties[nameof(u.Name)].Errors.Add("FirstName is required");
                    }
                    else if (u.Name.Length < 3)
                    {
                        u.Properties[nameof(u.Name)].Errors.Add("FirstName must be more then 3 symbols");
                    }
                    if (string.IsNullOrEmpty(u.LastName))
                    {
                        u.Properties[nameof(u.LastName)].Errors.Add("FirstName is required");
                    }
                    if (string.IsNullOrEmpty(u.Email))
                    {
                        u.Properties[nameof(u.Email)].Errors.Add("Email is required");
                    }
                    else if (!new System.ComponentModel.DataAnnotations.EmailAddressAttribute().IsValid(u.Email))
                    {
                        u.Properties[nameof(u.Email)].Errors.Add("Must consist . and @");
                    }
                }
            };

            TempPerson = temp;
            TempPerson.Validate();
        }
        public void DoesFactoryReturnMaidsAndCostumers()
        {
            //arrange
            PersonFactory personFactory = new PersonFactory();
            TempPerson    tempMaid      = new TempPerson();
            TempPerson    tempCustomer  = new TempPerson();
            string        resultMaid;
            string        resultCustomer;

            //act
            IPerson maid         = personFactory.GetPerson("Maid", tempMaid);
            IPerson customer     = personFactory.GetPerson("Customer", tempCustomer);
            Type    typeMaid     = maid.GetType();
            Type    typeCostumer = customer.GetType();

            resultMaid     = typeMaid.Name.ToString();
            resultCustomer = typeCostumer.Name.ToString();

            //assert
            Assert.AreEqual("Maid", resultMaid);
            Assert.AreEqual("Customer", resultCustomer);
        }
        public override Task OnNavigatedToAsync(object parameter, NavigationMode mode, IDictionary <string, object> state)
        {
            if (parameter == null)
            {
                if (CachedAddingPerson != null)
                {
                    //Если последняя операций была Edit, то нужно вернуть пёрсона из операций Add
                    //Иначе продолжить создавать нового пёрсона
                    if (CurrentState == States.Edit)
                    {
                        Title        = "Adding new person";
                        CurrentState = States.Add;
                        TempPerson   = CachedAddingPerson;
                    }

                    return(Task.CompletedTask);
                }
            }
            else
            {
                if (CachedEditingPerson != null)
                {
                    //Если ID кэшировнного редактируемого пёрсона совпадает с ID входящим пёрсоном
                    //то значит редактируемый пёрсон в кэше и входящий одни и тот же пёрсон
                    if (CahcedID == (parameter as Person).Id)
                    {
                        //Если последняя операций была Add, то нужно вернуть пёрсона из операций Edit
                        //Иначе продолжить редактировать пёрсона
                        if (CurrentState == States.Add)
                        {
                            CurrentState = States.Edit;
                            TempPerson   = CachedEditingPerson;
                            Title        = $"Editing {TempPerson.FullName}";
                        }

                        return(Task.CompletedTask);
                    }
                    //Иначе это разные пёрсоны то тогда удалить хранящийся ID
                    else
                    {
                        CahcedID = null;
                    }
                }
            }

            currentPerson = parameter == null ? new Person()
            {
                Id = Guid.NewGuid().ToString()
            } : parameter as Person;

            var temp = new PersonProxy(currentPerson)
            {
                Name        = currentPerson.Name,
                LastName    = currentPerson.LastName,
                Email       = currentPerson.Email,
                DateOfBirth = currentPerson.DateOfBirth,
                Validator   = i =>
                {
                    var u = i as PersonProxy;
                    if (string.IsNullOrEmpty(u.Name))
                    {
                        u.Properties[nameof(u.Name)].Errors.Add("FirstName is required");
                    }
                    else if (u.Name.Length < 3)
                    {
                        u.Properties[nameof(u.Name)].Errors.Add("FirstName must be more then 3 symbols");
                    }
                    if (string.IsNullOrEmpty(u.LastName))
                    {
                        u.Properties[nameof(u.LastName)].Errors.Add("FirstName is required");
                    }
                    if (string.IsNullOrEmpty(u.Email))
                    {
                        u.Properties[nameof(u.Email)].Errors.Add("Email is required");
                    }
                    else if (!new System.ComponentModel.DataAnnotations.EmailAddressAttribute().IsValid(u.Email))
                    {
                        u.Properties[nameof(u.Email)].Errors.Add("Must consist . and @");
                    }
                }
            };

            TempPerson = temp;
            TempPerson.Validate();


            if (parameter == null)
            {
                CurrentState = States.Add;
                Title        = "Adding new person";
            }
            else
            {
                CurrentState = States.Edit;
                Title        = $"Editing {TempPerson.FullName}";
            }

            return(Task.CompletedTask);
        }