Пример #1
0
        private SupplierDTO Create(SupplierViewModel viewModel)
        {
            try
            {
                log.Debug(SupplierViewModel.FormatSupplierViewModel(viewModel));

                SupplierDTO supplier = new SupplierDTO();

                // copy values
                viewModel.UpdateDTO(supplier, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                supplier.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                supplier.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_supplierService.AddSupplier - " + SupplierDTO.FormatSupplierDTO(supplier));

                int id = _supplierService.AddSupplier(supplier);

                supplier.SupplierId = id;

                log.Debug("result: 'success', id: " + id);

                return(supplier);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Пример #2
0
        private SupplierDTO Update(SupplierViewModel viewModel)
        {
            try
            {
                log.Debug(SupplierViewModel.FormatSupplierViewModel(viewModel));

                // get
                log.Debug("_supplierService.GetSupplier - supplierId: " + viewModel.SupplierId + " ");

                var existingSupplier = _supplierService.GetSupplier(viewModel.SupplierId);

                log.Debug("_supplierService.GetSupplier - " + SupplierDTO.FormatSupplierDTO(existingSupplier));

                if (existingSupplier != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingSupplier, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_supplierService.UpdateSupplier - " + SupplierDTO.FormatSupplierDTO(existingSupplier));

                    _supplierService.UpdateSupplier(existingSupplier);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingSupplier: null, SupplierId: " + viewModel.SupplierId);
                }

                return(existingSupplier);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }