예제 #1
0
        public async Task <IActionResult> AddCommitment(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var pet = await _context.Pets
                      .Include(p => p.Owner)
                      .FirstOrDefaultAsync(p => p.Id == id.Value);

            if (pet == null)
            {
                return(NotFound());
            }

            var view = new CommitmentViewModel
            {
                PetOwnerId = pet.Owner.Id,
                PetId      = pet.Id,
                Customers  = _combosHelper.GetComboCustomers(),
                Price      = 0,
                StartDate  = DateTime.Today,
                EndDate    = DateTime.Today.AddYears(1)
            };

            return(View(view));
        }
예제 #2
0
        public async Task <IActionResult> AddCommitment(CommitmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var commitment = await _converterHelper.ToCommitmentAsync(model, true);

                _context.Commitments.Add(commitment);
                await _context.SaveChangesAsync();

                return(RedirectToAction($"{nameof(DetailsPet)}/{model.PetId}"));
            }
            model.Customers = _combosHelper.GetComboCustomers();
            return(View(model));
        }
예제 #3
0
        public async Task <IActionResult> EditCommitment(CommitmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                var commitment = await _converterHelper.ToCommitmentAsync(model, false);

                _context.Commitments.Update(commitment);
                await _context.SaveChangesAsync();

                return(RedirectToAction($"{nameof(DetailsPet)}/{model.PetOwnerId}"));
            }

            return(View(model));
        }
예제 #4
0
 public async Task <Commitment> ToCommitmentAsync(CommitmentViewModel view, bool isNew)
 {
     return(new Commitment
     {
         Id = isNew ? 0 : view.Id,
         EndDate = view.EndDate,
         IsActive = view.IsActive,
         Customer = await _context.Customers.FindAsync(view.CustomerId),
         PetOwner = await _context.PetOwners.FindAsync(view.PetOwnerId),
         Price = view.Price,
         Pet = await _context.Pets.FindAsync(view.PetId),
         Remarks = view.Remarks,
         StartDate = view.StartDate,
     });
 }
예제 #5
0
        public CommitmentPage(CommitmentViewModel commitment)
        {
            _commitment = commitment;

            BackgroundColor = Constants.HtBoxDarkBrown;
            BindingContext  = commitment;

            var grid = new Grid()
            {
                RowDefinitions = new RowDefinitionCollection {
                    new RowDefinition(),
                    new RowDefinition(),
                },
                ColumnDefinitions = new ColumnDefinitionCollection {
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(2, GridUnitType.Star)
                    },
                }
            };

            var plannedLabel = new Label
            {
                Text            = "I am",
                TextColor       = Constants.HtBoxTan,
                BackgroundColor = Constants.HtBoxDarkBrown
            };

            plannedLabel.SetValue(Grid.RowProperty, 0);

            var plannedTextCell = new TextCell
            {
            };

            plannedTextCell.SetBinding(TextCell.TextProperty, "Status");
            grid.Children.Add(plannedLabel);

            Content = grid;
        }
예제 #6
0
 public CommitmentViewEventArgs(string segueName, CommitmentViewModel viewModel)
 {
     SegueName = segueName;
     ViewModel = viewModel;
 }