private void UpdateGameTaskEntityRelations(GameTask existGameTask, GameTaskDto newGameTask) { #region Updating Conditions IList <Condition> conditionsForDelete = existGameTask.Conditions.ToList(); foreach (ConditionDto newCondition in newGameTask.Conditions) { if (newCondition.Id > 0) { Condition existCondition = existGameTask.Conditions.First(r => r.Id == newCondition.Id); conditionsForDelete.Remove(existCondition); UpdateConditionEntity(existCondition, newCondition); } else { ConditionRepository.Insert(newCondition.MapTo <Condition>()); } } ConditionRepository.RemoveRange(conditionsForDelete); #endregion #region Updating Tips IList <Tip> tipsForDelete = existGameTask.Tips.ToList(); foreach (TipDto newTip in newGameTask.Tips) { if (newTip.Id > 0) { Tip existTip = existGameTask.Tips.First(r => r.Id == newTip.Id); tipsForDelete.Remove(existTip); UpdateTipEntity(existTip, newTip); } else { TipRepository.Insert(newTip.MapTo <Tip>()); } } TipRepository.RemoveRange(tipsForDelete); #endregion }
public CreateOutput <TipDto, long> Create(CreateInput <TipDto, long> input) { throw new NotSupportedException("This method is implemented but it is not safely to use it."); Tip newTipEntity = input.Entity.MapTo <Tip>(); if (!TipPolicy.CanCreateEntity(newTipEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"Tip\""); } TipRepository.Includes.Add(r => r.LastModifierUser); TipRepository.Includes.Add(r => r.CreatorUser); TipDto newTipDto = (TipRepository.Insert(newTipEntity)).MapTo <TipDto>(); TipRepository.Includes.Clear(); return(new CreateOutput <TipDto, long>() { CreatedEntity = newTipDto }); }