public BufferHours ValidateAndUpdate(BufferHours entity) { ExStoreToWorld ex = new ExStoreToWorld(entity.StoreWorldID); if (ex.Entity != null) { bool bModified = false; BufferHours buffer = ex.BufferHours(entity.Year); if (buffer == null) { entity.ID = 0; entity.ValueWeek = BufferHours.GetWeekStepValue(entity); //Math.Round(entity.Value*60 / DateTimeHelper.GetCountWeekInYear(entity.Year)); bModified = true; } else { if (buffer.Value != entity.Value) { buffer.Value = entity.Value; buffer.ValueWeek = BufferHours.GetWeekStepValue(buffer); //Math.Round(buffer.Value * 60 / DateTimeHelper.GetCountWeekInYear(buffer.Year)); entity = buffer; bModified = true; } } //if (entity.IsNew) //{ // if (buffer == null) // { // bModified = true; // } // else // { // if (buffer.Value != entity.Value) // { // buffer.Value = entity.Value; // buffer.ValueWeek = Math.Round(buffer.ValueWeek / DateTimeHelper.GetCountWeekInYear(buffer.Year)); // entity = buffer; // bModified = true; // } // } //} //else //{ // if (buffer == null) // { // bModified = true; // } // else // { // if (buffer.Value != entity.Value) // { // buffer.Value = entity.Value; // buffer.ValueWeek = Math.Round(buffer.ValueWeek / DateTimeHelper.GetCountWeekInYear(buffer.Year)); // entity = buffer; // bModified = true; // } // } //} if (bModified) { SaveOrUpdate(entity); WorldAvailableBufferHoursManager world_availble_buffer_manager = new WorldAvailableBufferHoursManager(ex.Entity, entity.Year); world_availble_buffer_manager.Load(); world_availble_buffer_manager.CheckAndBuildAllYearEntity(); world_availble_buffer_manager.RecalculateAfterChangedBufferValue(); } return(entity); } return(null); }
private void FillCommonInfoForWorld(WorldPlanningInfo worldinfo, StoreToWorld storeworld, DateTime begin, DateTime end) { short year = (short)DateTimeHelper.GetYearByDate(begin); PersonMinMax personMinMax = ExStoreToWorld.GetPersonMinMax(storeworld, year); WorldAvailableBufferHoursManager availBufferHours = new WorldAvailableBufferHoursManager(storeworld, begin); AvgAmount avgamount = _avgamountservice.GetAvgAmountByYear(CountryId, year); worldinfo.StoreWorldId = storeworld.ID; if (personMinMax != null) { worldinfo.MinimumPresence = personMinMax.Min; worldinfo.MaximumPresence = personMinMax.Max; } if (availBufferHours.BufferHours != null && availBufferHours.BufferHours.Value != 0) { worldinfo.AvailableWorldBufferHours = Convert.ToInt32(availBufferHours.GetPrevAvailableBufferForWeek(begin) + availBufferHours.BufferHoursPerWeek); } else worldinfo.AvailableWorldBufferHours = Int32.MinValue; if (!worldinfo.IsCashDesk) { Benchmark benchmark = ExStoreToWorld.GetBenchmark(storeworld, year);//_benchmarkservice.GetBenchmark(storeworld.ID, year); if (benchmark != null) worldinfo.Benchmark = benchmark.Value; } }