public ComponentStocks CalculateNewStocks(ComponentUpdate componentUpdate, List <Component> componentList) { ComponentStocks componentStocks = new ComponentStocks(); for (int i = 0; i < componentList.Count; i++) { if (componentList[i].ComponentName == "Milk") { componentStocks.MilkInStock = componentList[i].Stock - componentUpdate.MilkNeed; if (componentUpdate.ExtraMilk) { componentStocks.MilkInStock -= 1; } } else if (componentList[i].ComponentName == "Coffe") { componentStocks.CoffeInStock = componentList[i].Stock - componentUpdate.CoffeNeed; if (componentUpdate.ExtraCoffe) { componentStocks.CoffeInStock -= 1; } } else if (componentList[i].ComponentName == "Water") { componentStocks.WaterInStock = componentList[i].Stock - componentUpdate.WaterNeed; if (componentUpdate.ExtraWater) { componentStocks.WaterInStock -= 1; } } } return(componentStocks); }
public ComponentStocks ConfirmOrder(ComponentUpdate componentUpdate) { ComponentHelper componentHelper = new ComponentHelper(); using (var ctx = new CoffeShopContext()) { List <Component> componentList = ctx.Components.ToList(); var componentStocks = componentHelper.CalculateNewStocks(componentUpdate, componentList); for (int i = 0; i < componentList.Count; i++) { if (componentList[i].ComponentName == "Milk") { componentList[i].Stock = componentStocks.MilkInStock; } else if (componentList[i].ComponentName == "Coffe") { componentList[i].Stock = componentStocks.CoffeInStock; } else if (componentList[i].ComponentName == "Water") { componentList[i].Stock = componentStocks.WaterInStock; } } ctx.SaveChanges(); return(componentStocks); } }
public IActionResult ConfirmOrder([FromBody] ComponentUpdate componentUpdate) { ComponentBussiness component = new ComponentBussiness(); ComponentStocks componentStocks = component.ConfirmOrder(componentUpdate); return(Ok(componentStocks)); }
public async Task <NodeEntry> UpdateComponent([FromRoute] ComponentUpdate nodeBody, [FromQuery] IncludeFieldsQueryParams queryParams) { var nodeEntryBeforeUpdate = await _alfrescoHttpClient.GetNodeInfo(nodeBody.ComponentId); var nodeEntryAfterUpdate = await _nodesService.ComponentUpdate(nodeBody, ImmutableList <Parameter> .Empty.AddQueryParams(queryParams)); try { var documentEntry = await _alfrescoHttpClient.GetNodeInfo(nodeBody?.NodeId); var difference = _alfrescoModelComparer.CompareProperties( nodeEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), nodeEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary()); try { var componentsJson = difference.FirstOrDefault(x => x.Key == SpisumNames.Properties.ComponentVersionJSON); if (componentsJson != null) { difference.Remove(componentsJson); } } catch { } string messageDocument = TransactinoHistoryMessages.GetMessagePropertiesChange(TransactinoHistoryMessages.DocumentComponentUpdateDocument, difference); string messageFile = TransactinoHistoryMessages.GetMessagePropertiesChange(TransactinoHistoryMessages.DocumentComponentUpdateFile, difference); await _auditLogService.Record( documentEntry?.Entry?.Id, SpisumNames.NodeTypes.Component, nodeEntryBeforeUpdate?.GetPid(), NodeTypeCodes.Komponenta, EventCodes.Uprava, nodeEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), nodeEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), messageDocument); var fileId = await _documentService.GetDocumentFileId(documentEntry?.Entry?.Id); if (fileId != null) { await _auditLogService.Record( fileId, SpisumNames.NodeTypes.Component, nodeEntryBeforeUpdate?.GetPid(), NodeTypeCodes.Komponenta, EventCodes.Uprava, nodeEntryBeforeUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), nodeEntryAfterUpdate?.Entry?.Properties?.As <JObject>().ToDictionary(), messageFile); } } catch (Exception ex) { Log.Logger?.Error(ex, "Audit log failed"); } return(nodeEntryAfterUpdate); }
private static Update DeserializeUpdate(ComponentUpdate update, World world) { var schemaDataOpt = update.SchemaData; if (!schemaDataOpt.HasValue) { throw new ArgumentException($"Can not deserialize an empty {nameof(ComponentUpdate)}"); } return(Serialization.DeserializeUpdate(schemaDataOpt.Value)); }
public ResSubmit CapNhatThanhPhanDataType(ComponentUpdate componentUpdate) { tongcuclamnghiepEntities tongcuclamnghiep = new tongcuclamnghiepEntities(); ResSubmit resSubmit = new ResSubmit(true, "Cập nhật thành công"); var _Component = tongcuclamnghiep.m_component.Where(a => a.header_id == componentUpdate.HeaderId && a.reporttable_id == componentUpdate.IdBaoCao && a.orderrow == componentUpdate.RowId).FirstOrDefault(); if (!tongcuclamnghiep.m_reporttable.Any(a => a.id == componentUpdate.IdBaoCao)) { resSubmit = new ResSubmit(false, "Không có báo cáo này"); } if (resSubmit.success && _Component == null) { resSubmit = new ResSubmit(false, "Không có thành phần này"); } if (resSubmit.success) { if (_Component.m_header.is_no == true || _Component.m_header.is_component == true) { _Component.componentname = componentUpdate.Title; _Component.typevalue = 1; } else { _Component.typevalue = componentUpdate.TypeValue; } if (tongcuclamnghiep.SaveChanges() != 1) { resSubmit = new ResSubmit(false, "Cập nhật thất bại"); } else { TableComponent tableComponent = new TableComponent(); tableComponent.RowId = componentUpdate.RowId; List <HeaderComponent> headers = new List <HeaderComponent>(); tongcuclamnghiep.m_component.Where(a => a.orderrow == componentUpdate.RowId && a.reporttable_id == componentUpdate.IdBaoCao).ToList().ForEach(b => { headers.Add(new HeaderComponent() { Id = b.header_id.Value, Title = b.componentname, TypeValue = b.typevalue.Value, TextAlign = b.m_header.valuetextalign, TextBold = b.m_header.is_valuebold.Value, TextUpper = b.m_header.is_valueupper.Value }); }); tableComponent.headers = headers; resSubmit.extend = tableComponent; } } return(resSubmit); }
/*******************************************/ /**** Component Update Methods ****/ /*******************************************/ protected virtual void UpdateComponentDetails(ComponentUpdate update) { if (update != null) { Name = update.Name; NickName = update.Name; Description = update.Description; if (m_attributes is PrototypeAttribute && Caller.SelectedItem != null) { ((PrototypeAttribute)m_attributes).Visible = Caller.SelectedItem.IsPrototype(); } } }
protected override void OnUpdate() { dirtyComponents = new NativeQueue <SerializedMessagesToSend.UpdateToSend>(Allocator.TempJob); var dirtyComponentsWriter = dirtyComponents.AsParallelWriter(); var marker = foreachMarker; Dependency = Entities.WithName("EntityAclReplication") .WithoutBurst() .WithAll <HasAuthority>() .WithChangeFilter <Component>() .ForEach((ref Component component, in SpatialEntityId entity) => { marker.Begin(); if (!component.IsDataDirty()) { marker.End(); return; } // Serialize component var schemaUpdate = SchemaComponentUpdate.Create(); Serialization.SerializeUpdate(component, schemaUpdate); component.MarkDataClean(); // Schedule update var componentUpdate = new ComponentUpdate(ComponentId, schemaUpdate); var update = new SerializedMessagesToSend.UpdateToSend(componentUpdate, entity.EntityId.Id); dirtyComponentsWriter.Enqueue(update); marker.End(); }) .ScheduleParallel(Dependency); spatialOsSendSystem.AddReplicationJobProducer(Dependency, dirtyComponents); dirtyComponents = default; }
public async Task <ComponentStocks> ConfirmOrderAsync(decimal milkNeed, decimal coffeNeed, decimal waterNeed, bool milkCheck, bool coffeCheck, bool waterCheck) { var httpClient = new HttpClient(); var servicePath = new ServicePath(); ComponentUpdate componentUpdate = new ComponentUpdate(); componentUpdate.MilkNeed = milkNeed; componentUpdate.CoffeNeed = coffeNeed; componentUpdate.WaterNeed = waterNeed; componentUpdate.ExtraMilk = milkCheck; componentUpdate.ExtraCoffe = coffeCheck; componentUpdate.ExtraWater = waterCheck; var serialazeJSON = JsonConvert.SerializeObject(componentUpdate); var returnResult = await httpClient.PutAsync(servicePath.ServiceURL + "component/confirmorder", new StringContent(serialazeJSON, Encoding.UTF8, "application/json")); var contents = await returnResult.Content.ReadAsStringAsync(); ComponentStocks response = JsonConvert.DeserializeObject <ComponentStocks>(contents); return(response); }
/// <summary> /// Triggers component update /// </summary> internal void InvokeComponentUpdate() { // Invoke component's update event ComponentUpdate?.Invoke(this, EventArgs.Empty); }