Example #1
0
        public ActionResult Edit(PrinterDTO req)
        {
            Response res = new Response();

            if (ModelState.IsValid)
            {
                try
                {
                    if (req.Id > 0)
                    {
                        res.Data = _printerRepository.Update(req);
                    }
                    else
                    {
                        res.Data = _printerRepository.Create(req);
                    }
                }
                catch (Exception ex)
                {
                    res.Message = ex.Message;
                }
            }
            else
            {
                res.Data    = false;
                res.Message = string.Join(",", ModelState
                                          .SelectMany(ms => ms.Value.Errors)
                                          .Select(e => e.ErrorMessage));
            }

            return(Json(res, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public IActionResult UpdatePrinter(int printerID, string printerName, string printerModel)
        {
            var printer = new Printer();

            printer.Printer_ID    = printerID;
            printer.Printer_Name  = printerName;
            printer.Printer_Model = printerModel;


            _printerRepository.Update(printer);

            return(Json(printer));
        }
Example #3
0
        /// <summary>
        /// update printer database
        /// </summary>
        /// <param name="key"></param>
        /// <param name="facilityKey"></param>
        /// <param name="printer"></param>
        /// <returns></returns>
        public async Task UpdatePrinter(Guid key, Guid facilityKey, PrinterRequest printer)
        {
            var printerModel = await _printerModelRepository.GetAsync(printer.PrinterModelKey);

            if (printerModel == null)
            {
                throw new InvalidPrinterException(Resource.ResourceManager.GetString($"E{ErrorCode.InvalidInput}"), ErrorCode.InvalidInput);
            }

            var dataModel =
                await _printerRepository.GetAsync(key);

            if (dataModel == null)
            {
                throw new InvalidPrinterException(Resource.ResourceManager.GetString($"E{ErrorCode.ResourceNotFound}"), ErrorCode.ResourceNotFound);
            }

            _mapper.Map(printer, dataModel);

            _printerRepository.Update(dataModel);
            _unitOfWork.CommitChanges();
        }