/// <summary> /// <para> - Add/Create the CommodityGroup</para> /// </summary> /// <param name="commodityGroup"> /// <para> - CommodityGroup to Create. Object Fully Loaded.</para> /// </param> /// <returns> /// <para> - CommodityGroup Created with its assigned primary key.</para> /// <para> - Objects in its saved state.</para> /// </returns> public async Task <CommodityGroup> CreateCommodityGroup(CommodityGroup commodityGroup) { // - Shield creation from subscriber entirely var commodityGroupCreated = new CommodityGroup() { CommodityGroupCode = commodityGroup.CommodityGroupCode, CommodityGroupDescription = commodityGroup.CommodityGroupDescription }; foreach (var commodity in commodityGroup.Commodities) { var commodityCreated = new DbContext.Commodity() { CommodityCode = commodity.CommodityCode, CommodityDescription = commodity.CommodityDescription }; commodityGroupCreated.Commodities.Add(commodityCreated); } // - To the database mc_KomodoDbContext.CommodityGroups.Add(commodityGroupCreated); await mc_KomodoDbContext.SaveChangesAsync(); // - BACK to the future!!! return(commodityGroupCreated); }
/// <summary> /// <para> CommodityGroup to be removed/deleted.</para> /// </summary> /// <param name="commodityGroupId"> /// <para>Identifier of the CommodityGroup to be removed/deleted.</para> /// </param> /// <returns> /// <para> - All data of the CommodityGroup 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 <CommodityGroup> DeleteCommodityGroup(int commodityGroupId) { var commodityGroupDeleted = await mc_KomodoDbContext.CommodityGroups .Include(CmdGrp => CmdGrp.Commodities) .FirstOrDefaultAsync(CmdGrp => CmdGrp.CommodityGroupId == commodityGroupId); CommodityGroup commodityGroupUndo = null; // - If the executed is dead do not kill him again... if (commodityGroupDeleted != null) { // - Build a new unrelated object that can be used for undo purposes commodityGroupUndo = new CommodityGroup(); commodityGroupUndo.CommodityGroupCode = commodityGroupDeleted.CommodityGroupCode; commodityGroupUndo.CommodityGroupDescription = commodityGroupDeleted.CommodityGroupDescription; foreach (var commodityDeleted in commodityGroupDeleted.Commodities) { var commodityUndo = new DbContext.Commodity() { CommodityCode = commodityDeleted.CommodityCode, CommodityDescription = commodityDeleted.CommodityDescription }; commodityGroupUndo.Commodities.Add(commodityUndo); } // - WHO? Gets the Chop? mc_KomodoDbContext.CommodityGroups.Remove(commodityGroupDeleted); await mc_KomodoDbContext.SaveChangesAsync(); } return(commodityGroupUndo); }
public async Task GetCommodityGroup() { // - Given var resources = new Resources(); var commodityGroupId = 2; // - Setup the Mock to Repository CommodityGroup commodityGroup = TestSetup.BuildCommodityGroup(commodityGroupId); resources.Repository.Setup(Rps => Rps.GetCommodityGroup(commodityGroupId)) .Returns(Task.FromResult <CommodityGroup>(commodityGroup)); // - When var result = await resources.Controller.GetCommodityGroup(commodityGroupId); // - Then Assert.IsNotNull(result); var okObjectResult = result.Result as OkObjectResult; Assert.AreEqual(200, okObjectResult.StatusCode); var commodityGroupResult = okObjectResult.Value as CommodityGroup; Assert.AreEqual(commodityGroupId, commodityGroupResult.CommodityGroupId); Assert.AreEqual(commodityGroup.CommodityGroupCode, commodityGroupResult.CommodityGroupCode); Assert.AreEqual(commodityGroup.CommodityGroupDescription, commodityGroupResult.CommodityGroupDescription); Assert.AreEqual(commodityGroup.Commodities.Count, commodityGroupResult.Commodities.Count); }
public async Task DeleteCommodityGroup() { // - Given var resources = new Resources(); var commodityGroupId = 2; // - Setup the Mock to Repository CommodityGroup commodityGroupOut = TestSetup.BuildCommodityGroup(0); resources.Repository.Setup(Rps => Rps.DeleteCommodityGroup(commodityGroupId)) .Returns(Task.FromResult <CommodityGroup>(commodityGroupOut)); // - When var result = await resources.Controller.DeleteCommodityGroup(commodityGroupId); // - Then Assert.IsNotNull(result); var okObjectResult = result.Result as OkObjectResult; Assert.AreEqual(200, okObjectResult.StatusCode); var commodityGroupResult = okObjectResult.Value as CommodityGroup; Assert.AreEqual(0, commodityGroupResult.CommodityGroupId); // - returns an undo object that is ready to be inserted again. Assert.AreEqual(commodityGroupOut.CommodityGroupCode, commodityGroupResult.CommodityGroupCode); Assert.AreEqual(commodityGroupOut.CommodityGroupDescription, commodityGroupResult.CommodityGroupDescription); Assert.AreEqual(commodityGroupOut.Commodities.Count, commodityGroupResult.Commodities.Count); }
internal static CommodityGroup BuildCommodityGroup(int commodityGroupId) { var commodityGroup = new CommodityGroup() { CommodityGroupId = commodityGroupId, CommodityGroupCode = "0002", CommodityGroupDescription = "CommodityGroup2", Commodities = new List <Commodity>() { new Commodity() { CommodityId = 1, CommodityCode = "001", CommodityDescription = "Commodity001" }, new Commodity() { CommodityId = 2, CommodityCode = "002", CommodityDescription = "Commodity002" }, new Commodity() { CommodityId = 3, CommodityCode = "003", CommodityDescription = "Commodity003" } } }; return(commodityGroup); }
/// <summary> /// Retrieve Airline infromation from database /// </summary> /// <param name="recordID">Record id according to which touple is to be retrieved</param> /// <returns></returns> public CommodityGroup GetCommodityGroupRecord(string recordID, string UserSNo) { try { CommodityGroup commodityGroup = new CommodityGroup(); SqlParameter[] Parameters = { new SqlParameter("@SNo", recordID), new SqlParameter("@UserSNo", recordID) }; SqlDataReader dr = SqlHelper.ExecuteReader(DMLConnectionString.WebConfigConnectionString, CommandType.StoredProcedure, "GetRecordCommodityGroup", Parameters); if (dr.Read()) { commodityGroup.SNo = Convert.ToInt32(dr["SNo"]); commodityGroup.StartRange = (dr["StartRange"].ToString()); commodityGroup.EndRange = (dr["EndRange"].ToString()); commodityGroup.GroupName = Convert.ToString(dr["GroupName"]); commodityGroup.IsActive = Convert.ToBoolean(dr["IsActive"]); commodityGroup.Active = dr["Active"].ToString(); commodityGroup.CreatedBy = dr["CreatedUser"].ToString(); commodityGroup.UpdatedBy = dr["UpdatedUser"].ToString(); } dr.Close(); return(commodityGroup); } catch (Exception ex)// { throw ex; } }
public void Add(CommodityGroup commodityGroup) { foreach (var a in commodityGroup.Inventory) { Add(a.Key, a.Value); } }
public string MakeSaleArgument(ArgumentType argumentType) { var arg = SaleArguments.First(a => a.Type == argumentType); HasMadeSalesPitch = true; if (ShakeDown) { CurrentComment = "I don't care."; Patience--; } else if (arg.LikesArgument.Any(Buyer.LeaderTraits.Contains)) { CurrentComment = $"I like {argumentType} stuff. This is my new offer."; //TODO: test that it is not possible to get lower amount CurrentOffer = Buyer.Inventory.GetResourcesOfValue(CurrentOffer.GetValue() * 2); } else if (arg.DislikesArgument.Any(Buyer.LeaderTraits.Contains)) { CurrentComment = $"Why would I like {argumentType} stuff!? You Moron!"; Patience /= 2; } else { CurrentComment = $"So..."; Patience--; } OnUpdate.Invoke(); //TODO: actually use this in player speech bubble return(arg.Text); }
/// <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); } }
/// <summary> /// <para> CommodityGroup to be removed/deleted.</para> /// </summary> /// <param name="commodityGroupId"> /// <para>Identifier of the CommodityGroup to be removed/deleted.</para> /// </param> /// <returns> /// <para> - All data of the CommodityGroup 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.CommodityGroup> DeleteCommodityGroup(int commodityGroupId) { var commodityGroupUndo = new CommodityGroup(); var serviceUrl = string.Empty; serviceUrl = mc_Configuration["DomainServices:Commodity:DeleteCommodityGroup"]; serviceUrl += commodityGroupId.ToString(); using (var response = await mc_CommodityHttpClient.DeleteAsync(serviceUrl)) { if (!response.IsSuccessStatusCode) { string message = "Error occurred in CommodityRepositoryToService.DeleteCommodityGroup."; message += "Response StatusCode : " + response.StatusCode + ". "; message += "Response Message : " + response.ReasonPhrase + ". "; mc_Logger.LogError(message); } else { var commodityGroupUndoJson = response.Content.ReadAsStringAsync().Result; commodityGroupUndo = JsonConvert.DeserializeObject <CommodityGroup>(commodityGroupUndoJson); } } return(commodityGroupUndo); }
/// <summary> /// <para> - Update/Edit the CommodityGroup</para> /// </summary> /// <param name="commodityGroup"> /// <para> - CommodityGroup to be updated...</para> /// <para> - Object fully loaded.</para> /// </param> /// <returns> /// <para> - CommodityGroup updated.</para> /// <para> - Object in its saved state.</para> /// </returns> public async Task <Models.Commodity.CommodityGroup> UpdateCommodityGroup(Models.Commodity.CommodityGroup commodityGroup) { var commodityGroupUpdated = new CommodityGroup(); var serviceUrl = string.Empty; serviceUrl = mc_Configuration["DomainServices:Commodity:UpdateCommodityGroup"]; // - Load up our trusty the Http var commodityGroupStringContent = new StringContent(JsonConvert.SerializeObject(commodityGroup), Encoding.UTF8, "application/json"); using (var response = await mc_CommodityHttpClient.PutAsync(serviceUrl, commodityGroupStringContent)) { if (!response.IsSuccessStatusCode) { var message = "Error occurred in CommodityRepositoryToService.UpdateCommodityGroup."; message += "Response Status Code : " + response.StatusCode; message += "Response Message : " + response.ReasonPhrase; } else { var commodityGroupUpdatedJson = response.Content.ReadAsStringAsync().Result; commodityGroupUpdated = JsonConvert.DeserializeObject <CommodityGroup>(commodityGroupUpdatedJson); } } return(commodityGroupUpdated); }
private void StartShakeDown() { CurrentOffer = new CommodityGroup(); CurrentComment = $"That's nice! How about you give it to me and I will make sure nothing bad happens to you."; Patience = 3; CurrentTradeState = TradeState.Negotiating; OnUpdate.Invoke(); }
//TODO: are the commodities checked against inventory first? public void CounterOffer(CommodityGroup additionals) //Dictionary<Commodity,int> addons, { int additionalsValue = additionals.GetValue(); if (ShakeDown) { CurrentComment = "it would be a shame if something happened to this nice shop."; Patience--; } else if (additionalsValue < Patience) { CurrentOffer.Add(additionals); TradeSuccess(); } else if (additionalsValue < Patience * 2) { //will suggest less if (additionals.GetAmount() > 1) { CurrentComment = "What about this?"; CurrentOffer.Add(additionals.GetResourcesOfValue(additionals.GetValue() - 1)); Patience /= 2; } else { CurrentComment = "nah.."; Patience--; } } else if (additionalsValue < Patience * 4) { CurrentComment = "That's too much."; Patience--; } else { CurrentComment = "No! I'm outta here. See ya!"; TradeFailure(); } OnUpdate.Invoke(); }
public void Substract(CommodityGroup commodityGroup) { foreach (var a in commodityGroup.Inventory) { //TODO: should it go to negative? if (Inventory.ContainsKey(a.Key)) { Inventory[a.Key] -= a.Value; } else { Debug.LogWarning("Trying to subtract a commodity below zero: " + a.Key.name); } } }
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 async Task <ActionResult <Commodity> > UpdateCommodityGroup(CommodityGroup commodityGroup) { try { var commodityGroupExtant = await mc_CommodityRepository.UpdateCommodityGroup(commodityGroup); if (commodityGroupExtant == null) { return(NotFound()); } return(Ok(commodityGroupExtant)); } catch (Exception exception) { string message = "Error occurred in CommodityController.UpdateCommodityGroup" + Environment.NewLine; message += exception.Message; return(StatusCode(StatusCodes.Status500InternalServerError, message)); } }
private void StartTrade() { int artAptitude = 0; if (CurrentArt.Colors.Contains(WantedColor)) { artAptitude++; } if (CurrentArt.Properties.Contains(WantedProperty)) { artAptitude++; } CurrentOffer = Buyer.Inventory.GetResourcesOfValue(Random.Range(CurrentArt.Value / 5, CurrentArt.Value + Patience)); switch (artAptitude) { case 0: Patience = Buyer.Attitude / 2; CurrentComment = $"That's not really what I wanted. I can give you <b>{CurrentOffer.AsText()}</b>"; break; case 1: Patience = Buyer.Attitude; CurrentComment = $"Alright. I can give you <b>{CurrentOffer.AsText()}</b> for that"; break; case 2: Patience = Buyer.Attitude + 5; CurrentComment = $"That's perfect! I will give you <b>{CurrentOffer.AsText()}</b>"; break; } CurrentTradeState = TradeState.Negotiating; OnUpdate.Invoke(); }
internal static List <CommodityGroup> BuildCommodityGroups() { int commodityGroupDepth = 5; var commodityGroups = new List <CommodityGroup>(); var commodities = new List <Commodity>(); for (int commodityGroupIndex = 1; commodityGroupIndex <= commodityGroupDepth; commodityGroupIndex++) { var commodityGroupId = commodityGroups.Count < 1 ? 1 : 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 Commodity() { CommodityId = commodities.Count < 1 ? 1 : commodities.Max(Cmd => Cmd.CommodityId) + 1, CommodityCode = "CMD" + commodityIndex.ToString("000"), CommodityDescription = "Commodity Description " + commodityIndex.ToString("000"), CommodityGroupId = commodityGroupId }; commodities.Add(commodity); commodityGroup.Commodities.Add(commodity); } // - Load it up, strap it down!!! commodityGroups.Add(commodityGroup); } return(commodityGroups); }
/// <summary> /// <para> - Update/Edit the CommodityGroup</para> /// </summary> /// <param name="commodityGroup"> /// <para> - CommodityGroup to be updated...</para> /// <para> - Object fully loaded.</para> /// </param> /// <returns> /// <para> - CommodityGroup updated.</para> /// <para> - Object in its saved state.</para> /// </returns> public async Task <CommodityGroup> UpdateCommodityGroup(CommodityGroup commodityGroup) { var commodityGroupExtant = await mc_KomodoDbContext.CommodityGroups .Include(CmdGrp => CmdGrp.Commodities) .FirstOrDefaultAsync(CmdGrp => CmdGrp.CommodityGroupId == commodityGroup.CommodityGroupId); if (commodityGroupExtant == null) { return(commodityGroup); } commodityGroupExtant.CommodityGroupCode = commodityGroup.CommodityGroupCode; commodityGroupExtant.CommodityGroupDescription = commodityGroup.CommodityGroupDescription; foreach (var commodity in commodityGroup.Commodities) { var commodityExtant = await mc_KomodoDbContext.Commodities.FirstOrDefaultAsync(Cmd => Cmd.CommodityId == commodity.CommodityId); if (commodityExtant == null) { commodityExtant = new DbContext.Commodity() { CommodityCode = commodity.CommodityCode, CommodityDescription = commodity.CommodityDescription }; commodityGroupExtant.Commodities.Add(commodityExtant); } else { commodityExtant.CommodityCode = commodity.CommodityCode; commodityExtant.CommodityDescription = commodity.CommodityDescription; } } await mc_KomodoDbContext.SaveChangesAsync(); return(commodityGroupExtant); }
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)); }
public void Setup(Community buyer, CommodityGroup currentOffer) { OnOffer.Clear(); foreach (var i in InitializedObjects) { Destroy(i); } foreach (var rin in buyer.Inventory) { var res = (KeyValuePair <Commodity, int>)rin; var r = res.Key; int max = res.Value - currentOffer.GetResourceAmount(r); if (max <= 0) { continue; } var o = Instantiate(OfferPrefab, OfferPrefab.transform.parent); o.Max = max; o.ResourceNameText.text = r.name; o.ResourceImage.sprite = r.Sprite; o.gameObject.SetActive(true); o.AmountInputField.onValueChanged.AddListener(v => UpdateResourceInOffer(v, r)); InitializedObjects.Add(o.gameObject); } Holder.SetActive(true); }
//Returns true if they contain the same keys and values public bool Equals(CommodityGroup other) { return(Inventory.Count == other.Inventory.Count && !Inventory.Except(other.Inventory).Any()); }
public void RemoveCommodities(CommodityGroup commodities) { Inventory.Substract(commodities); }
public static CommodityGroup ToEntity(this CommodityGroupModel model, CommodityGroup destination) { return(AutoMapperConfiguration.Mapper.Map(model, destination)); }
public static CommodityGroupModel ToModel(this CommodityGroup entity) { return(AutoMapperConfiguration.Mapper.Map <CommodityGroup, CommodityGroupModel>(entity)); }
public ViewResult Create() { var commodityGroup = new CommodityGroup(); return(View("Save", commodityGroup)); }