Beispiel #1
0
        public async Task <ActionResult <CommodityGroup> > CreateCommodityGroup(CommodityGroup commodityGroup)
        {
            try
            {
                var commodityGroupCreated = await mc_CommodityRepository.CreateCommodityGroup(commodityGroup);

                return(Ok(commodityGroupCreated));
            }
            catch (Exception exception)
            {
                string message = "Error occurred in CommodityController.CreateCommodityGroup" + Environment.NewLine;
                message += exception.Message;
                return(StatusCode(StatusCodes.Status500InternalServerError, message));
            }
        }
        public IActionResult Save(CommodityGroup commodityGroup)
        {
            CommodityGroup commodityGroupSaved;

            if (ModelState.IsValid)
            {
                if (commodityGroup.CommodityGroupId < 1)
                {
                    var commodityGroupCreatedResult = mc_CommodityRepository.CreateCommodityGroup(commodityGroup);
                    commodityGroupSaved = commodityGroupCreatedResult.Result as CommodityGroup;
                }
                else
                {
                    var commodityGroupUpdatedResult = mc_CommodityRepository.UpdateCommodityGroup(commodityGroup);
                    commodityGroupSaved = commodityGroupUpdatedResult.Result as CommodityGroup;
                }

                return(View("Details", commodityGroupSaved));
            }

            // - Someting went wrong. Try again!
            return(View("Save", commodityGroup));
        }