Exemplo n.º 1
0
        public async Task <ActionResult> Edit(EditReturn model)
        {
            if (ModelState.IsValid)
            {
                var totalQuantity = model.ReturnItems.Sum(r => r.Quantity);
                if (totalQuantity == 0)
                {
                    ModelState.AddModelError(string.Empty, "Quantity must be specified for each least one item.");
                }
            }

            if (!ModelState.IsValid)
            {
                foreach (var itemModel in model.ReturnItems)
                {
                    itemModel.Quantities = ModelFactory.GetQuantitySelectList(itemModel.MaxQuantity);
                }

                return(View(model));
            }

            var returnId = model.ReturnId;

            var actionData = this.GetActionData();

            switch (actionData?.ActionName)
            {
            case Actions.Save:
                returnId = await SaveReturn(model);

                break;
            }

            return(RedirectToAction("Index", "Return", new { id = returnId }));
        }
Exemplo n.º 2
0
        private async Task <long> SaveReturn(EditReturn model)
        {
            if (model.ReturnId == null)
            {
                var mCreateReturnItems = new List <MFulfillment_CreateReturnItem>();
                foreach (var item in model.ReturnItems)
                {
                    mCreateReturnItems.Add(new MFulfillment_CreateReturnItem()
                    {
                        ReturnRequestItemId = item.ReturnRequestItemId,
                        Quantity            = item.Quantity
                    });
                }

                var mCreateReturn = new MFulfillment_CreateReturn()
                {
                    CreateDateTimeUtc = Locale.GetUtcFromLocalTime(model.ReturnDate.Value),
                    CreateReturnItems = mCreateReturnItems
                };

                var aCreateReturn = new AReturn_CreateReturn()
                {
                    MCreateReturn = mCreateReturn
                };

                var returnId = await ReturnAdminService.CreateReturnAsync(aCreateReturn);

                return(returnId);
            }
            else
            {
                var mUpdateReturnItems = new List <MFulfillment_UpdateReturnItem>();
                foreach (var item in model.ReturnItems)
                {
                    mUpdateReturnItems.Add(new MFulfillment_UpdateReturnItem()
                    {
                        ReturnItemId = item.ReturnItemId.Value,
                        Quantity     = item.Quantity
                    });
                }

                var mUpdateReturn = new MFulfillment_UpdateReturn()
                {
                    CreateDateTimeUtc = Locale.GetUtcFromLocalTime(model.ReturnDate.Value),
                    UpdateReturnItems = mUpdateReturnItems
                };

                var aUpdateReturn = new AReturn_UpdateReturn()
                {
                    MUpdateReturn = mUpdateReturn
                };

                await ReturnAdminService.UpdateReturnAsync(aUpdateReturn);

                return(model.ReturnId.Value);
            }
        }