/// <summary>
        /// - Build up the list of CommodityGroups with child Commodities
        /// </summary>
        private void BuildCommodityGroupsMock(int commodityGroupDepth)
        {
            for (int commodityGroupIndex = 1; commodityGroupIndex <= commodityGroupDepth; commodityGroupIndex++)
            {
                var commodityGroupId = mc_CommodityGroups.Count < 1 ? 1 :  mc_CommodityGroups.Max(CmdGrp => CmdGrp.CommodityGroupId) + 1;

                var commodityGroup = new CommodityGroup()
                {
                    CommodityGroupId          = commodityGroupId,
                    CommodityGroupCode        = "GRP" + commodityGroupIndex.ToString("000"),
                    CommodityGroupDescription = "Group Description " + commodityGroupIndex.ToString("000")
                };

                // - Gather the children, Margeretha,
                //   there is a spin on the horizon,
                //   and its commin' our way!!!
                for (int commodityIndex = 1; commodityIndex <= commodityGroupDepth; commodityIndex++)
                {
                    var commodity = new Models.Commodity.Commodity()
                    {
                        CommodityId          = mc_Commodities.Count < 1 ? 1 : mc_Commodities.Max(Cmd => Cmd.CommodityId) + 1,
                        CommodityCode        = "CMD" + commodityIndex.ToString("000"),
                        CommodityDescription = "Commodity Description " + commodityIndex.ToString("000"),
                        CommodityGroupId     = commodityGroupId
                    };

                    mc_Commodities.Add(commodity);
                    commodityGroup.Commodities.Add(commodity);
                }

                // - Load it up, strap it down!!!
                mc_CommodityGroups.Add(commodityGroup);
            }
        }
示例#2
0
        /// <summary>
        /// <para> Commodity to be removed/deleted.</para>
        /// </summary>
        /// <param name="commodityId">
        /// <para>Identifier of the Commodity to be removed/deleted.</para>
        /// </param>
        /// <returns>
        /// <para> - All data of the Commodity removed/deleted </para>
        /// <para>   in a ready for insert-state (keys=-1)</para>
        /// <para>   to facilitate undo by re-insert...</para>
        /// </returns>
        public async Task <Models.Commodity.Commodity> DeleteCommodity(int commodityId)
        {
            Models.Commodity.Commodity commodityUndo = new Models.Commodity.Commodity();
            var serviceUrl = string.Empty;

            serviceUrl  = mc_Configuration["DomainServices:Commodity:DeleteCommodity"];
            serviceUrl += commodityId.ToString();

            using (var response = await mc_CommodityHttpClient.DeleteAsync(serviceUrl))
            {
                if (!response.IsSuccessStatusCode)
                {
                    string message = "Error occurred in CommodityRepositoryToService.DeleteCommodity";
                    message += "Response Status Code : " + response.StatusCode;
                    message += "Response Message : " + response.ReasonPhrase;
                    mc_Logger.LogError(message);
                }
                else
                {
                    string commodityJson = response.Content.ReadAsStringAsync().Result;
                    commodityUndo = JsonConvert.DeserializeObject <Models.Commodity.Commodity>(commodityJson);
                }
            }

            return(commodityUndo);
        }
示例#3
0
        /// <summary>
        /// <para> - Update/Edit the Commodity</para>
        /// </summary>
        /// <param name="commodity">
        /// <para> - Commodity to be updated...</para>
        /// <para> - Object fully loaded.</para>
        /// </param>
        /// <returns>
        /// <para> - Commodity updated.</para>
        /// <para> - Object in its saved state.</para>
        /// </returns>
        public async Task <Models.Commodity.Commodity> UpdateCommodity(Models.Commodity.Commodity commodity)
        {
            var    commodityUpdated = new Models.Commodity.Commodity();
            string serviceUrl       = string.Empty;

            serviceUrl = mc_Configuration["DomainServices:Commodity:UpdateCommodity"];

            // - Load up the Http
            var commodityStringContent = new StringContent(JsonConvert.SerializeObject(commodity), Encoding.UTF8, "application/json");

            using (var response = await mc_CommodityHttpClient.PutAsync(serviceUrl, commodityStringContent))
            {
                if (!response.IsSuccessStatusCode)
                {
                    string message = "Message : Error occurred in CommodityRepositoryToService.UpdateCommodity";
                    message += "Response Status Code : " + response.StatusCode;
                    message += "Response Message : " + response.ReasonPhrase;
                    mc_Logger.LogError(message);
                }
                else
                {
                    string commodityJson = response.Content.ReadAsStringAsync().Result;
                    commodityUpdated = JsonConvert.DeserializeObject <Models.Commodity.Commodity>(commodityJson);
                }
            }

            return(commodityUpdated);
        }
 /// <summary>
 /// <para> - Update/Edit the Commodity</para>
 /// </summary>
 /// <param name="commodity">
 /// <para> - Commodity to be updated...</para>
 /// <para> - Object fully loaded.</para>
 /// </param>
 /// <returns>
 /// <para> - Commodity updated.</para>
 /// <para> - Object in its saved state.</para>
 /// </returns>
 public async Task <Models.Commodity.Commodity> UpdateCommodity(Models.Commodity.Commodity commodity)
 {
     throw new System.NotImplementedException();
 }