private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (e.NavigationParameter != null)
            {
                var name = e.NavigationParameter.ToString();
                DefaultViewModel["PersonName"] = name;
                _source = App.MainVm.SearchPerson(name);
                DefaultViewModel["Person"] = _source;
            }
            if (_filterList == null)
            {
                _filterList = new List <Filter>()
                {
                    new Filter("My Movies", _source.Movies, this.MovieGridCtrl.ItemTemplate),
                    new Filter("Other Movies", _source.External, this.MovieGridCtrl.ItemTemplate),
                    new Filter("TV Shows", _source.TVShows, this.MovieGridCtrl.ItemTemplate),
                    new Filter("Episodes", _source.Episodes, EpisodeTemplate),
                };
            }
            this.DefaultViewModel["Filters"]     = _filterList;
            this.DefaultViewModel["ShowFilters"] = _filterList.Count > 1;

            object filterIndex;

            if (e.PageState != null && e.PageState.TryGetValue("ActiveFilter", out filterIndex))
            {
                foreach (var filter in _filterList)
                {
                    filter.Active = false;
                }
                _filterList[(int)filterIndex].Active = true;
            }
        }
        public async Task <IActionResult> Update([FromBody] PersonVm data)
        {
            return(await ServiceInvoker.AsyncOk(async() =>
            {
                if (!data.Id.HasValue)
                {
                    var newItem = Mapper.Map <Person>(data);

                    newItem = await _personRepository.SaveAsync(newItem);

                    return Mapper.Map <PersonVm>(newItem);
                }

                var existingItem =
                    await _personRepository.GetOneAsync(data.Id.Value);

                if (existingItem == null)
                {
                    throw new NotFoundException(nameof(Person), data.Id.Value);
                }

                existingItem = Mapper.Map(data, existingItem);

                existingItem = await _personRepository.SaveAsync(existingItem);

                return Mapper.Map <PersonVm>(existingItem);
            }));
        }
Beispiel #3
0
        // PUT api/account/5
        public HttpResponseMessage Put(int id, [FromBody] PersonVm userProfileVm)
        {
            var user = this.personService.GetById(id);

            if (user.UserId != userService.CurrentUserId)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (userProfileVm.ContactInformation.Email1 != user.ContactInformation.Email1)
                    {
                        emailHelper.SendEmailAddressChanged(user.FirstName, user.ContactInformation.Email1);
                    }
                    var person = userProfileVm.ToModel(this.userService.CurrentUserId);
                    this.personService.Save(person);
                    userProfileVm = PersonVm.FromModel(person);
                    return(Request.CreateResponse(HttpStatusCode.Accepted));
                }
                catch (Exception e)
                {
                    emailHelper.SendErrorEmail(e);
                }
            }
            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
Beispiel #4
0
        public async Task <Person> Create(PersonVm personVm)
        {
            Person person = EditCommonPersonProperties(new Person(), personVm);

            await _personsRepository.Create(person);

            return(person);
        }
Beispiel #5
0
        public async Task <Person> Edit(PersonVm personVm)
        {
            Person personFromDb = await _personsRepository.GetOne(personVm.Id.Value);

            personFromDb = EditCommonPersonProperties(personFromDb, personVm);

            await _personsRepository.Update(personFromDb);

            return(personFromDb);
        }
        public async Task <IActionResult> Post([FromBody] PersonVm personVm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Person person = await _editPersonsService.Create(personVm);

            return(CreatedAtAction(nameof(Get), new { id = person.Id }, person));
        }
Beispiel #7
0
        private Person EditCommonPersonProperties(Person person, PersonVm personVm)
        {
            person.FirstName      = personVm.FirstName;
            person.LastName       = personVm.LastName;
            person.PersonalNumber = personVm.PersonalNumber;
            person.BirthDate      = personVm.BirthDate;
            person.Gender         = personVm.Gender;
            person.Salary         = personVm.Salary;

            return(person);
        }
Beispiel #8
0
        public static PersonDm Map(PersonVm vm)
        {
            var dm = new PersonDm
            {
                FirstName   = vm.FirstName,
                LastName    = vm.LastName,
                Email       = vm.Email,
                DateOfBirth = Convert.ToDateTime(vm.DateOfBirth)
            };

            return(dm);
        }
Beispiel #9
0
        public static PersonVm Map(PersonDm dm)
        {
            var vm = new PersonVm
            {
                FirstName   = dm.FirstName,
                LastName    = dm.LastName,
                Email       = dm.Email,
                DateOfBirth = dm.DateOfBirth.ToString("MM/dd/yyyy")
            };

            return(vm);
        }
Beispiel #10
0
        public IHttpActionResult GetPerson(PersonVm person)
        {
            try
            {
                PersonBLL.SavePerson(person);

                return(Ok("Save was successful!"));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
Beispiel #11
0
        //public Admin ToModel(int userId){
        //    return new Admin
        //    {
        //        Id = this.Id,
        //        DateVerified = this.DateVerified,
        //        Person = this.Person.ToModel(userId),
        //        VerificationNotes = this.VerificationNotes,
        //        Verified = this.Verified
        //    };
        //}

        internal static AdminVm FromModel(Admin admin)
        {
            if (admin.Person == null)
            {
                admin.Person = new Person();
            }
            return(new AdminVm {
                Id = admin.Id,
                DateVerified = admin.DateVerified,
                Person = PersonVm.FromModel(admin.Person),
                VerificationNotes = admin.VerificationNotes,
                Verified = admin.Verified
            });
        }
        public async Task <IActionResult> Put([FromBody] PersonVm personVm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (personVm.Id == null)
            {
                return(BadRequest());
            }

            await _editPersonsService.Edit(personVm);

            return(NoContent());
        }
Beispiel #13
0
        private void MainWindow_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            DebugUtils.Write("MainWindow_OnMouseUP!");

            if (_isWindowOpen)
            {
                return;
            }

            _draggingWindow.Close();


            PersonVm personVm = _personVm;

            if (personVm == null)
            {
                return;
            }

            var window = new LayoutWindow();

            window.WindowStartupLocation = WindowStartupLocation.Manual;

            var point = PointToScreen(Mouse.GetPosition(null));

            window.Width  = 500;
            window.Height = 500;
            window.Left   = point.X;
            window.Top    = point.Y;

            var anotherVm = new MainViewModel();

            anotherVm.Persons.Clear();
            anotherVm.Persons.Add(personVm);

            window.DataContext = anotherVm;

            _isWindowOpen = true;
            window.Show();
            window.Closing += WindowOnClosing;

            this.ReleaseMouseCapture();
        }
Beispiel #14
0
        private void OnListBoxPreviewMouseButtonDown(object sender, MouseButtonEventArgs e)
        {
            DebugUtils.Write("ListBox_MouseLeft_DOWN");


            if (_isWindowOpen)
            {
                return;
            }
            else
            {
                this.CaptureMouse();
            }

            var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                DebugUtils.Write($"ListBox_item - {item}");
                _personVm = item.DataContext as PersonVm;
            }

            _draggingWindow = new DraggingWindow();
            _draggingWindow.WindowStartupLocation = WindowStartupLocation.Manual;

            var point = PointToScreen(Mouse.GetPosition(null));

            _draggingWindow.Width              = 500;
            _draggingWindow.Height             = 500;
            _draggingWindow.Left               = point.X;
            _draggingWindow.Top                = point.Y;
            _draggingWindow.Opacity            = 0.5;
            _draggingWindow.AllowsTransparency = true;
            _draggingWindow.WindowStyle        = WindowStyle.None;
            _draggingWindow.Background         = new SolidColorBrush(Colors.Transparent);

            _draggingWindow.Show();
        }
Beispiel #15
0
        // GET: Admin
        public ActionResult Index()
        {
            List <PersonVm> db          = new List <PersonVm>();
            string          queryString = @"SELECT * FROM Persons";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand com = new SqlCommand(queryString, connection);
                connection.Open();

                SqlDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    PersonVm person = new PersonVm();
                    person.FirstName    = reader["FirstName"].ToString();
                    person.LastName     = reader["LastName"].ToString();
                    person.EmailAddress = reader["EmailAddress"].ToString();
                    person.Quote        = Convert.ToDecimal(reader["Quote"]);
                    db.Add(person);
                }
            }
            return(View(db));
        }
Beispiel #16
0
        public virtual ActionResult Index()
        {
            PersonVm userProfileVm = null;

            try
            {
                var person = this.personService.Get(this.webSecurityService.CurrentUserId);

                if (person != null)
                {
                    userProfileVm = PersonVm.FromModel(person);
                }
                else
                {
                    userProfileVm = new PersonVm();
                }
                return(View(userProfileVm));
            }
            catch (Exception e)
            {
                this.emailHelper.SendErrorEmail(e as Exception);
            }
            return(View(WENEEDUHAVE.Error.Views.Index));
        }
        public async Task <IActionResult> LoadData([DataSourceRequest] DataSourceRequest request)
        {
            var gridInfo = new List <PersonVm>();

            for (int i = 0; i < 10; i++)
            {
                var p = new PersonVm
                {
                    Name     = $"NTest_{i.ToString()}",
                    Lastname = $"LTest_{i.ToString()}",
                    DoB      = new DateTime(1960, 1 + i, 10 + i)
                };

                gridInfo.Add(p);
            }


            var gridData = new DataSourceResult {
                Data = gridInfo, Total = gridInfo.Count
            };
            var jsonResult = Json(gridData);

            return(jsonResult);
        }
Beispiel #18
0
        public static void SavePerson(PersonVm person)
        {
            var personDm = PersonMapper.Map(person);

            PersonDAL.SavePersonData(personDm);
        }
Beispiel #19
0
 private async Task <int> SaveToDB(PersonVm model)
 {
     return(0);
 }
Beispiel #20
0
        public async Task <IActionResult> SavePersonAsync(/* [Bind("Name, Lastname, DoB, ")] */ PersonVm model)
        {
            if (ModelState.IsValid)
            {
                var ret = await SaveToDB(model);

                if (0 == ret)
                {
                    TempData["Success"] = "1";
                    return(RedirectToAction(nameof(HomeController.Index)));
                }
            }

            return(View("Index", model));
        }