예제 #1
0
        public UsedProductViewModel CreateViewModel(int id, int orderId, int isoId)
        {
            var prod = repository.GetContext().UsedProducts
                       .Include(p => p.Stocks)
                       .FirstOrDefault(p => p.UsedProductId == id);

            var model = new UsedProductViewModel();

            if (prod != null)
            {
                model = Mapper.Map <UsedProduct, UsedProductViewModel>(prod);
                var stock = prod.Stocks.FirstOrDefault();
                if (stock != null)
                {
                    model.Stock = Mapper.Map <UsedProductStock, UsedProductStockViewModel>(stock);
                }
            }
            else
            {
                var order = repository.GetById <IntegrationOrder>(orderId);
                model.Stock.IntegrationOrderId   = order.Id;
                model.Stock.IntegrationOrderName = order.Name;
                model.Stock.IsolatorId           = isoId;
            }

            model.VtmList = new SelectList(GetAllVtms(), "VtmId", "DrugName", model.VtmId);
            var locations = GetAllStorageLocation().Select(p => new { Value = p.StorageLocationId, Text = string.Format("{0} ({1})", p.LocationName, p.LocationCode) });

            model.Stock.StorageLocationList = new SelectList(locations, "Value", "Text", model.Stock.StorageLocationId);

            return(model);
        }
예제 #2
0
        public UsedProduct MapViewModelToUsedProduct(UsedProductViewModel model, string user, bool proceedSave)
        {
            var prod = GetUsedProductById(model.UsedProductId);

            prod = prod == null?Mapper.Map <UsedProductViewModel, UsedProduct>(model) : Mapper.Map(model, prod);

            if (!proceedSave)
            {
                return(prod);
            }

            if (prod.UsedProductId > 0)
            {
                prod.SetUpdateDetails(user);
                repository.SaveExisting(prod);
            }
            else
            {
                prod.SetCreateDetails(user);
                repository.SaveNew(prod);
            }

            var stock = repository.GetById <UsedProductStock>(model.Stock.UsedProductStockId);

            stock = stock == null?Mapper.Map <UsedProductStockViewModel, UsedProductStock>(model.Stock) : Mapper.Map(model.Stock, stock);

            stock.UsedProductId = prod.UsedProductId;
            stock.StockStatusId = (int)StockStatusEnum.Available;

            if (stock.UsedProductStockId > 0)
            {
                stock.SetUpdateDetails(user);
                repository.SaveExisting(stock);
            }
            else
            {
                stock.SetCreateDetails(user);
                repository.SaveNew(stock);
            }

            return(prod);
        }
예제 #3
0
        public ActionResult SaveUsedProduct(UsedProductViewModel model)
        {
            var response = usedProdService.MapViewModelToUsedProduct(model, GetCurrentUserId(), true);

            return(Json(response.UsedProductId > 0));
        }