Exemplo n.º 1
0
        /// <summary>
        /// Get SupplierType by id
        /// </summary>
        /// <param name="id">SupplierType id</param>
        /// <returns>SupplierType json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_supplierTypeService.GetSupplierType - supplierTypeId: " + id + " ");

                var supplierType = new SupplierTypeViewModel(_supplierTypeService.GetSupplierType(id));

                log.Debug("_supplierTypeService.GetSupplierType - " + SupplierTypeViewModel.FormatSupplierTypeViewModel(supplierType));

                log.Debug("result: 'success'");

                //return Json(supplierType, JsonRequestBehavior.AllowGet);
                //return Content(JsonConvert.SerializeObject(supplierType), "application/json");
                //return supplierType;
                //return JsonConvert.SerializeObject(supplierType);
                return(Ok(supplierType));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Exemplo n.º 2
0
        private SupplierTypeDTO Create(SupplierTypeViewModel viewModel)
        {
            try
            {
                log.Debug(SupplierTypeViewModel.FormatSupplierTypeViewModel(viewModel));

                SupplierTypeDTO supplierType = new SupplierTypeDTO();

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

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

                // add
                log.Debug("_supplierTypeService.AddSupplierType - " + SupplierTypeDTO.FormatSupplierTypeDTO(supplierType));

                int id = _supplierTypeService.AddSupplierType(supplierType);

                supplierType.SupplierTypeId = id;

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

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

                throw;
            }
        }
Exemplo n.º 3
0
        //[ValidateAntiForgeryToken]
        /// <summary>
        /// Updates data for an existing SupplierType, or creates a new SupplierType if the Id is 0
        /// </summary>
        /// <param name="viewModel">SupplierType data</param>
        /// <returns>SupplierType id</returns>
        public IHttpActionResult Upsert(SupplierTypeViewModel viewModel)
        {
            log.Debug("Upsert");

            if (viewModel.SupplierTypeId > 0)
            {
                var t = Update(viewModel);
                //return Json(true);
                //return JsonConvert.SerializeObject(t.SupplierTypeId);
                return(Ok(t.SupplierTypeId));
            }
            else
            {
                var t = Create(viewModel);
                //return Json(t.SupplierTypeId);
                //return JsonConvert.SerializeObject(t.SupplierTypeId);
                return(Ok(t.SupplierTypeId));
            }
        }
Exemplo n.º 4
0
        private SupplierTypeDTO Update(SupplierTypeViewModel viewModel)
        {
            try
            {
                log.Debug(SupplierTypeViewModel.FormatSupplierTypeViewModel(viewModel));

                // get
                log.Debug("_supplierTypeService.GetSupplierType - supplierTypeId: " + viewModel.SupplierTypeId + " ");

                var existingSupplierType = _supplierTypeService.GetSupplierType(viewModel.SupplierTypeId);

                log.Debug("_supplierTypeService.GetSupplierType - " + SupplierTypeDTO.FormatSupplierTypeDTO(existingSupplierType));

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

                    // update
                    log.Debug("_supplierTypeService.UpdateSupplierType - " + SupplierTypeDTO.FormatSupplierTypeDTO(existingSupplierType));

                    _supplierTypeService.UpdateSupplierType(existingSupplierType);

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

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

                throw;
            }
        }
Exemplo n.º 5
0
        //[ValidateAntiForgeryToken]
        /// <summary>
        /// Save a list of SupplierType
        /// </summary>
        /// <param name="viewModels">SupplierType view models</param>
        /// <param name="id">(not used)</param>
        /// <returns>true if the operation is successfull</returns>
        public IHttpActionResult SaveList(SupplierTypeViewModel[] viewModels, int?id)
        {
            try
            {
                log.Debug("SaveList");

                if (viewModels != null)
                {
                    // save list
                    foreach (SupplierTypeViewModel viewModel in viewModels)
                    {
                        log.Debug(SupplierTypeViewModel.FormatSupplierTypeViewModel(viewModel));

                        if (viewModel.SupplierTypeId > 0)
                        {
                            var t = Update(viewModel);
                        }
                        else
                        {
                            var t = Create(viewModel);
                        }
                    }
                }
                else
                {
                    log.Error("viewModels: null");
                }

                //return Json(true);
                //return JsonConvert.SerializeObject(true);
                return(Ok(true));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }