public IHttpActionResult GetDependentById(int id) { var dependent = appdb.Dependents.FirstOrDefault(c => c.Id == id); if (dependent == null) { return(NotFound()); } var model = new DependentViewModel() { Name = dependent.Name, Age = dependent.Age, Id = dependent.Id, ImageData = dependent.Image, SchoolYear = dependent.SchoolYear, DayLimit = dependent.DayLimit, DependentCredit = dependent.DependentCredit, CustomerId = dependent.CustomerId, Restricts = dependent.Restricts.Select(i => new MenuItemViewModel() { Id = i.Id, Name = i.Name, Price = i.Price, Type = i.Type, Description = i.Description }).AsQueryable().ToList() }; return(Ok(new { dependent = model })); }
public void ChangeViewModelPropertyVerifyPropertyChangeIsRaisedAlsoForTheDependentProperties() { var viewModel = new DependentViewModel { Primary = "Value1" }; viewModel.Primary = "Value2"; viewModel.ChangeList.Should().Have.SameSequenceAs(primary, dependent, primary, dependent); }
public void ChangeViewModelPropertyVerifyPropertyChangeIsRaisedAlsoForTheDependentProperties() { var viewModel = new DependentViewModel { Primary = "Value1" }; viewModel.Primary = "Value2"; viewModel.ChangeList.Should().BeSameAs(new [] { primary, dependent, primary, dependent }); }
public IHttpActionResult AddDependentRestricts([FromBody] DependentViewModel dependent) { var dependentObject = appdb.Dependents.FirstOrDefault(i => i.Id == dependent.Id); if (dependentObject != null) { foreach (var restrict in dependent.Restricts) { var restrictToAdd = appdb.MenuItems.FirstOrDefault(ad => ad.Id == restrict.Id); dependentObject.Restricts.Add(restrictToAdd); } } appdb.SaveChanges(); return(Ok()); }
public async Task <DependentViewModel> DependentById(int DependentId) { var d = await _dependentRepository.DependentById(DependentId); DependentViewModel dVM = new DependentViewModel(); dVM.DependentId = d.DependentId; dVM.TenantId = d.TenantId; dVM.FirstName = d.FirstName; dVM.LastName = d.LastName; dVM.Gender = d.Gender; dVM.Age = d.Age; dVM.Email = d.Email; dVM.Phone = d.Phone; dVM.Notes = d.Notes; return(dVM); }
public ActionResult Edit(EmployeeViewModel model) { try { if (ModelState.IsValid) { if (Session["DEPENDENT"] != null) { var deps = (List <DependentDto>)Session["DEPENDENT"]; foreach (var depDto in deps) { var dependente = new DependentViewModel(); dependente.Name = depDto.Nome; dependente.DependentId = depDto.Id; dependente.EmployeeId = model.EmployeeId; dependente.Employee = model; dependente.Excluido = depDto.Excluido; model.Dependents.Add(dependente); } } ViewBag.role = new SelectList(_roleAppService.GetAll(), "RoleId", "Name", model.RoleId); _employeeAppService.Update(model); return(RedirectToAction("Index")); } else { ViewBag.role = new SelectList(_roleAppService.GetAll(), "RoleId", "Name"); } return(View(model)); } catch (Exception ex) { return(View()); } }
public IHttpActionResult EditDependents(DependentViewModel dependent) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } var dependentToUpdate = appdb.Dependents.FirstOrDefault(d => d.Id == dependent.Id); if (dependentToUpdate != null) { dependentToUpdate.Age = dependent.Age; dependentToUpdate.DayLimit = dependent.DayLimit; dependentToUpdate.DependentCredit = dependent.DependentCredit; dependentToUpdate.Image = dependent.ImageData; dependentToUpdate.Name = dependent.Name; dependentToUpdate.SchoolYear = dependent.SchoolYear; } appdb.SaveChanges(); return(Ok()); }
public IHttpActionResult AddDependents(DependentViewModel dependent) { if (!ModelState.IsValid) { return(BadRequest("Invalid data.")); } var d = appdb.Dependents.Add(new Dependent() { Name = dependent.Name, Age = dependent.Age, Id = dependent.Id, Image = dependent.ImageData, SchoolYear = dependent.SchoolYear, DayLimit = dependent.DayLimit, DependentCredit = dependent.DependentCredit, CustomerId = dependent.CustomerId }); appdb.SaveChanges(); return(Ok()); }
public async Task <List <DependentViewModel> > DependentList(int TenantId) { List <Dependent> dependent = await _dependentRepository.DependentList(TenantId); List <DependentViewModel> dependentVM = new List <DependentViewModel>(); foreach (Dependent d in dependent) { DependentViewModel dVM = new DependentViewModel(); dVM.DependentId = d.DependentId; dVM.TenantId = d.TenantId; dVM.FirstName = d.FirstName; dVM.LastName = d.LastName; dVM.Gender = d.Gender; dVM.Age = d.Age; dVM.Email = d.Email; dVM.Phone = d.Phone; dVM.Notes = d.Notes; dependentVM.Add(dVM); } return(dependentVM); }