public async Task <IActionResult> EditProperty(PropertyCollectorViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var propertyCollector = await _converterHelper.ToPropertyCollectorAsync(viewModel, false);

                _dataContext.PropertyCollectors.Update(propertyCollector);
                await _dataContext.SaveChangesAsync();

                _flashMessage.Info("Registro editado con éxito.");
                return(RedirectToAction("Details", "Collectors", new { id = viewModel.CollectorId }));
            }

            return(View(viewModel));
        }
Ejemplo n.º 2
0
 public async Task <PropertyCollector> ToPropertyCollectorAsync(PropertyCollectorViewModel viewModel, bool isNew)
 {
     return(new PropertyCollector
     {
         Id = isNew ? 0 : viewModel.Id,
         Serie = viewModel.Serie,
         Company = viewModel.Company,
         Model = viewModel.Model,
         Colour = viewModel.Colour,
         IsAvailable = viewModel.IsAvailable,
         Price = viewModel.Price,
         Collector = await _dataContext.Collectors.FindAsync(viewModel.CollectorId),
         PropertyType = await _dataContext.PropertyTypes.FindAsync(viewModel.PropertyTypeId),
         PropertyCollectorImages = isNew ? new List <PropertyCollectorImage>() : viewModel.PropertyCollectorImages,
         Remarks = viewModel.Remarks
     });
 }
        public async Task <IActionResult> AddProperty(PropertyCollectorViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var propertyCollector = await _converterHelper.ToPropertyCollectorAsync(viewModel, true);

                _dataContext.PropertyCollectors.Add(propertyCollector);
                await _dataContext.SaveChangesAsync();

                _flashMessage.Confirmation("Registro creado con éxito.");
                return(RedirectToAction("Details", "Collectors", new { id = viewModel.CollectorId }));
            }

            viewModel.PropertyTypes = _combosHelper.GetComboPropertyTypes();

            return(View(viewModel));
        }
        public async Task <IActionResult> AddProperty(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var collector = await _dataContext.Collectors.FindAsync(id);

            if (collector == null)
            {
                return(NotFound());
            }
            var model = new PropertyCollectorViewModel
            {
                CollectorId   = collector.Id,
                PropertyTypes = _combosHelper.GetComboPropertyTypes()
            };

            return(View(model));
        }