Exemplo n.º 1
0
        public ActionResultDTO UpdateComputer(ComputerEntity computer)
        {
            var existingcomputer = GetComputer(computer.Id);

            if (existingcomputer == null)
            {
                return new ActionResultDTO {
                           ErrorMessage = "Computer Not Found", Id = 0
                }
            }
            ;

            computer.Mac = StringManipulationServices.FixMac(computer.Mac);
            var actionResult     = new ActionResultDTO();
            var validationResult = ValidateComputer(computer, "update");

            if (validationResult.Success)
            {
                _uow.ComputerRepository.Update(computer, computer.Id);

                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = computer.Id;
            }
            else
            {
                actionResult.Success      = false;
                actionResult.ErrorMessage = validationResult.ErrorMessage;
            }

            return(actionResult);
        }
Exemplo n.º 2
0
        public ActionResultDTO AddComputer(ComputerEntity computer)
        {
            var actionResult = new ActionResultDTO();

            computer.Mac = StringManipulationServices.FixMac(computer.Mac);
            var validationResult = ValidateComputer(computer, "new");

            if (validationResult.Success)
            {
                _uow.ComputerRepository.Insert(computer);
                _uow.Save();
                actionResult.Success = true;
                actionResult.Id      = computer.Id;
            }
            else
            {
                actionResult.Success      = false;
                actionResult.ErrorMessage = validationResult.ErrorMessage;
            }
            return(actionResult);
        }