public Response <bool> UpdateCampaighn(CampaighnEditModel model) { if ((model.StartLevel ?? 1) < 1 || (model.StartLevel ?? 1) > 100) { return(new Response <bool>(false, (int)ErrorEnum.Aplied, "Уровень должен быть в диапазоне 1-99")); } var transaction = _campaighnContext.StartTransaction(); var currentEntity = model.Id == null ? new Campaighn() : _campaighnContext.GetById((Guid)model.Id); var campaighnId = model.Id ?? Guid.NewGuid(); currentEntity.Name = model.Name; currentEntity.StartLevel = model.StartLevel ?? 1; IEnumerable <CampaighnRace> newRaces; if (!model.Id.Equals(null)) { var oldRaces = _campaighnRaceContext.GetList() .List() .Where(w => w.CampaighnId.Equals(model.Id) && !model.Subraces.Contains(w.SubraceId)); foreach (var oldRace in oldRaces) { _campaighnRaceContext.Delete(oldRace); } newRaces = model.Subraces.Where( w => !_campaighnRaceContext.GetList() .List() .Where(ww => ww.CampaighnId.Equals(model.Id)) .Select(ss => ss.SubraceId) .ToList() .Contains(w)).Select(s => new CampaighnRace { CampaighnId = campaighnId, SubraceId = s }); } else { newRaces = model.Subraces.Select(s => new CampaighnRace { CampaighnId = campaighnId, SubraceId = s }); } foreach (var newRace in newRaces) { _campaighnRaceContext.Upsert(newRace); } transaction.Commit(); return(new Response <bool>()); }
public Response <AttributeEditModel> GetAttributeEditModel(Guid attributeId) { if (attributeId.Equals(Guid.Empty)) { return(new Response <AttributeEditModel>(null, (int)ErrorEnum.NotFound, "Запись не найдена")); } var entity = _dictionaryAttrContext.GetById(attributeId); return(new Response <AttributeEditModel>(new AttributeEditModel { Id = entity.Id, Name = entity.Name, AttributeTypeId = entity.AttributeTypeId, Abbreviation = entity.Abbreviation, AttributeFunction = AttributeFunction.GetId(entity.AttributeFunction) })); }
public Response <bool> UpdateRace(RaceEditModel updateModel) { var transaction = _raceContext.StartTransaction(); var id = updateModel.Id ?? Guid.NewGuid(); var currentEntity = updateModel.Id == null ? new Race { Id = id } : _raceContext.GetById((Guid)updateModel.Id); currentEntity.Name = updateModel.Name; currentEntity.Description = updateModel.Description ?? ""; _raceContext.Upsert(currentEntity); updateModel.Attributes.SaveAttributes(id, _raceAttributeContext); transaction.Commit(); return(new Response <bool>(true)); }
public Response <bool> UpdateSubrace(SubraceListModel updateModel) { var currentEntity = updateModel.Id == null ? new Subrace() : _subraceContext.GetById((Guid)updateModel.Id); currentEntity.Name = updateModel.Name; currentEntity.Description = updateModel.Description ?? ""; currentEntity.RaceId = updateModel.RaceId; _subraceContext.Upsert(currentEntity); return(new Response <bool>(true)); }
public Response <bool> UpdateItemType(ItemTypeEditModel updateModel) { var currentEntity = updateModel.Id == null ? new ItemType() : _itemTypeContext.GetById((Guid)updateModel.Id); currentEntity.Name = updateModel.Name; currentEntity.Description = updateModel.Description ?? ""; currentEntity.RootId = updateModel.RootId; currentEntity.Plural = updateModel.Plural; _itemTypeContext.Upsert(currentEntity); return(new Response <bool>(true)); }