コード例 #1
0
        public ProductGroup UpdatedProductGroup(ProductGroup oldGroup, UpdatedProductGroupDto newProduct)
        {
            if (newProduct.ParentGroup != 0)
            {
                oldGroup.ParentGroup = newProduct.ParentGroup;
            }

            oldGroup.GroupName   = newProduct.GroupName;
            oldGroup.ParentGroup = newProduct.ParentGroup;

            // update description if only the value has changed
            if (oldGroup.Description == null && newProduct.Description != "" || oldGroup.Description != null && newProduct.Description == "" ||
                newProduct.Description.ToLower() != oldGroup.Description.ToLower())
            {
                oldGroup.Description = newProduct.Description;
            }

            return(oldGroup);
        }
コード例 #2
0
        public ActionResult UpdateProductGroup(uint id, [FromBody] UpdatedProductGroupDto updatedGroup)
        {
            if (updatedGroup == null || updatedGroup.Id != id)
            {
                return(StatusCode(400));
            }

            if (!ModelState.IsValid)
            {
                return(new InvalidInputResponse(ModelState));
            }

            var groupExist = _query.GetProductGroupById(id);

            if (groupExist == null)
            {
                return(StatusCode(404, "Product Group Not Found"));
            }

            if (updatedGroup.ParentGroup != 0)
            {
                var group = _query.GetProductGroupById((uint)updatedGroup.ParentGroup);

                if (group == null)
                {
                    ModelState.AddModelError("Parent Group", $"Parent Group with id: {updatedGroup.ParentGroup} Doesn't Exist");
                    return(new InvalidInputResponse(ModelState));
                }
            }

            var groupObj = _factory.UpdatedProductGroup(groupExist, updatedGroup);
            var result   = _command.UpdateProductGroup(groupObj);

            if (result == false)
            {
                return(StatusCode(500, "Unknown Error Occured try again later"));
            }

            return(StatusCode(204));
        }