public void RemoveListFromGroup(string groupPublicID, string listPublicID, string userName) { EveShoppingContext contexto = new EveShoppingContext(); eshGroupShoppingList sl; eshSnapshot snap; CommonTestGetForGroupShoppingListUpdate(groupPublicID, listPublicID, userName, contexto, out sl); LogicaSnapshots logicaSnap = new LogicaSnapshots(); snap = logicaSnap.SelectStaticListByPublicID(listPublicID); if (snap == null) { throw new ApplicationException(Messages.err_staticShoppingListNoExiste); } eshGroupShoppingListSnapshot gsls = contexto.eshGroupShoppingListSnapshots.Where(gs => gs.snapshotID == snap.snapshotID && gs.groupShoppingListID == sl.groupShoppingListID).FirstOrDefault(); if (gsls == null) { throw new ApplicationException(); } contexto.eshGroupShoppingListSnapshots.Remove(gsls); contexto.SaveChanges(); }
public void DeleteShoppingList(string publicID, string userName) { EveShoppingContext contexto = new EveShoppingContext(); using (TransactionScope scope = new TransactionScope()) { eshShoppingList sl = contexto.eshShoppingLists.Where(s => s.publicID == publicID).FirstOrDefault(); if (sl == null) { throw new ApplicationException(Messages.err_shoppingLisNoExiste); } if (sl.userID.HasValue && userName == null) { throw new ApplicationException(Messages.err_notOwner); } UserProfile user = contexto.UserProfiles.Where(u => u.UserName == userName).FirstOrDefault(); if (sl.userID.HasValue && sl.userID.Value != user.UserId) { throw new ApplicationException(Messages.err_notOwner); } //passed the user right test, the shopping list can be deleted based on the owner. //At this moment we dont make any further test regarding if the list used or not, it is possible to delete only based on the ownership. //Delete the related static lists LogicaSnapshots logicaSnaps = new LogicaSnapshots(); List <eshSnapshot> listSnapshots = sl.eshSnapshots.ToList(); foreach (var snp in listSnapshots) { logicaSnaps.DeleteStaticShoppingList(snp, userName, contexto); } List <eshShoppingListFitting> listFittings = sl.eshShoppingListFittings.ToList(); foreach (var fit in listFittings) { this.DeleteFitFromShoppingLIST(sl.shoppingListID, fit.fittingID, contexto); } List <eshShoppingListInvType> listInvtTypes = sl.eshShoppingListInvTypes.ToList(); foreach (var it in listInvtTypes) { this.DeleteItemFromShoppingList(sl.shoppingListID, it.typeID, contexto); } ClearAllDeltaFromSummary(sl, contexto); contexto.eshShoppingLists.Remove(sl); contexto.SaveChanges(); scope.Complete(); } }
public string AddListToGroup(string groupPublicID, string listPublicID, string userName, string nick, IImageResolver resolver = null) { EveShoppingContext contexto = new EveShoppingContext(); string snapPublicID = null; eshGroupShoppingList sl; eshSnapshot snap; CommonTestGetForGroupShoppingListUpdate(groupPublicID, listPublicID, userName, contexto, out sl); LogicaSnapshots logicaSnap = new LogicaSnapshots(); snap = logicaSnap.SelectStaticListByPublicID(listPublicID); //if not snapshot, we check if it is a normal list if (snap == null) { snap = logicaSnap.CreateStaticShoppingList(listPublicID, null, resolver); } // if not snapshot, we check if it is a group list //if (snap == null) //{ // snap = logicaSnap.CreateStaticShoppingListFromGroup(listPublicID, null, resolver); //} if (snap == null) { throw new ApplicationException(Messages.err_staticShoppingListNoExiste); } eshGroupShoppingListSnapshot rel = new eshGroupShoppingListSnapshot(); rel.groupShoppingListID = sl.groupShoppingListID; rel.nickName = nick; rel.snapshotID = snap.snapshotID; rel.creationDate = System.DateTime.Now; sl.dateUpdate = System.DateTime.Now; contexto.eshGroupShoppingListSnapshots.Add(rel); contexto.SaveChanges(); return(snap.publicID); }