public ActionResult SaveIssueItem(IssueItemModel model)
        {
            if (ModelState.IsValid)
            {
                var issueItem = _issueItemRepository.GetById(model.Id);

                //always set IsNew to false when saving
                issueItem.IsNew = false;
                issueItem       = model.ToEntity(issueItem);

                // unit conversion
                var item = _itemRepository.GetById(model.ItemId);
                if (item.UnitOfMeasureId != model.IssueUnitOfMeasureId)
                {
                    var uc = _unitConversionService.GetUnitConversion(model.IssueUnitOfMeasureId.Value, item.UnitOfMeasureId.Value);
                    issueItem.Quantity = issueItem.IssueQuantity * uc.ConversionFactor;
                }
                else
                {
                    issueItem.Quantity = issueItem.IssueQuantity;
                }

                //update issue cost
                _issueService.UpdateIssueCost(issueItem);
                _issueItemRepository.UpdateAndCommit(issueItem);
                return(new NullJsonResult());
            }
            else
            {
                return(Json(new { Errors = ModelState.Errors().ToHtmlString() }));
            }
        }
        private void PrepareIssueItemModel(IssueItemModel model)
        {
            model.CurrentQuantity = _storeService.GetTotalQuantity(null, model.StoreLocatorId, model.ItemId);

            var uoms = _unitConversionService.GetFromUOMs(model.ItemUnitOfMeasureId.Value);

            model.AvailableUnitOfMeasures.Add(new SelectListItem
            {
                Value = model.ItemUnitOfMeasureId.ToString(),
                Text  = model.ItemUnitOfMeasureName
            });
            foreach (var c in uoms)
            {
                model.AvailableUnitOfMeasures.Add(new SelectListItem
                {
                    Value    = c.Id.ToString(),
                    Text     = c.Name,
                    Selected = model.IssueUnitOfMeasureId == c.Id
                });
            }
        }
        public ActionResult CreateIssueItem(long issueId)
        {
            //need to get issue here to assign to new issueItem
            //so when mapping to Model, we will have StoreId as defined
            //in AutoMapper configuration
            var issue     = _issueRepository.GetById(issueId);
            var issueItem = new IssueItem
            {
                IsNew = true,
                Issue = issue
            };

            _issueItemRepository.Insert(issueItem);

            this._dbContext.SaveChanges();

            var model = new IssueItemModel();

            model = issueItem.ToModel();
            var html = this.IssueItemPanel(model);

            return(Json(new { Id = issueItem.Id, Html = html }));
        }
        public string IssueItemPanel(IssueItemModel model)
        {
            var html = this.RenderPartialViewToString("_IssueItemDetails", model);

            return(html);
        }