public void Save(PrinterViewModel printerViewModel)
        {
            Printer printer = new Printer(printerViewModel.Id);
            printer.Name = printerViewModel.Name;
            printer.Code = printerViewModel.Code;
            printer.EquipmentNumber = printerViewModel.EquipmentNumber;
            printer.Make = printerViewModel.Make;
            printer.Model = printerViewModel.Model;
            printer.EquipmentType = (EquipmentType)printerViewModel.EquipmentType;
            printer.Description = printerViewModel.Description;
            printer.CostCentre = (Hub)_hubRepository.GetById(printerViewModel.CostCentre);
            printer._Status = EntityStatus.Active;

            _equipmentRepository.Save(printer);
        }
        PrinterViewModel Map(Printer printer)
        {
            PrinterViewModel vm = new PrinterViewModel();
            vm.Id = printer.Id;
            vm.Code = printer.Code;
            vm.EquipmentNumber = printer.EquipmentNumber;
            vm.Name = printer.Name;
            vm.Make = printer.Make;
            vm.Model = printer.Model;
            vm.EquipmentType = (int)printer.EquipmentType;
            vm.Description = printer.Description;
            vm.CostCentre = printer.CostCentre.Id;
            vm.IsActive = (int)printer._Status;

            return vm;
        }
示例#3
0
        public ActionResult CreatePrinter(PrinterViewModel vm)
        {
            ViewBag.CostCentreList = _printerViewModelBuilder.CostCentres();
            ViewBag.EquipmentTypeList = _printerViewModelBuilder.EquipmentTypes();

            try
            {
                vm.Id = Guid.NewGuid();
                _printerViewModelBuilder.Save(vm);

                TempData["msg"] = "Printer Successfully Created";

                return RedirectToAction("ListPrinters");
            }
            catch (DomainValidationException ve)
            {
                ValidationSummary.DomainValidationErrors(ve, ModelState);
                _log.Debug("Failed to create Printer " + ve.Message);
                _log.Error("Failed to create Printer" + ve.ToString());

                return View(vm);
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                _log.Debug("Failed to create Printer " + ex.Message);
                _log.Error("Failed to create Printer" + ex.ToString());

                return View(vm);
            }

        }