Exemple #1
0
        public string CreateGroupList(string userName, string name, string description)
        {
            try
            {
                EveShoppingContext contexto = new EveShoppingContext();

                UserProfile up = contexto.UserProfiles.Where(u => u.UserName == userName).FirstOrDefault();
                if (up == null)
                {
                    throw new ApplicationException(Messages.err_usuarioNoExiste);
                }

                eshGroupShoppingList group =
                    new eshGroupShoppingList();
                group.dateCreation = DateTime.Now;
                group.dateUpdate   = DateTime.Now;
                group.name         = name;
                group.description  = description;
                group.publicID     = Guid.NewGuid().ToString();
                group.tradeHubID   = 30000142;
                group.userID       = up.UserId;

                contexto.eshGroupShoppingLists.Add(group);
                contexto.SaveChanges();

                return(group.publicID);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #2
0
        public EVListSummary SelectGroupListSummaryPorPublicID(string publicID, IImageResolver imageResolver)
        {
            EveShoppingContext   contexto     = new EveShoppingContext();
            eshGroupShoppingList shoppingList = contexto.eshGroupShoppingLists.Where(sl => sl.publicID == publicID).FirstOrDefault();

            if (shoppingList == null)
            {
                return(null);
            }

            EVListSummary summary =
                new EVListSummary();

            summary.Description      = shoppingList.description;
            summary.Name             = shoppingList.name;
            summary.PublicID         = shoppingList.publicID;
            summary.ReadOnlyPublicID = null;
            summary.ShoppingListID   = shoppingList.groupShoppingListID;

            Dictionary <int, EVFittingHardware> diccHwd = new Dictionary <int, EVFittingHardware>();

            //por cada snapshot que tenemos asociado
            foreach (var snapshot in shoppingList.eshGroupShoppingListSnapshots)
            {
                summary.TotalVolume += snapshot.eshSnapshot.totalVolume;
                foreach (var item in snapshot.eshSnapshot.eshSnapshotInvTypes)
                {
                    EVFittingHardware efth = null;
                    if (diccHwd.ContainsKey(item.typeID))
                    {
                        efth             = diccHwd[item.typeID];
                        efth.Volume     += item.volume.Value;
                        efth.TotalPrice += item.unitPrice * item.units;
                        efth.Units      += item.units;
                    }
                    else
                    {
                        efth = new EVFittingHardware()
                        {
                            Name       = item.invType.typeName,
                            ItemID     = item.typeID,
                            Units      = item.units,
                            Volume     = item.volume.Value,
                            UnitVolume = item.volume.Value / item.units,
                            TotalPrice = item.unitPrice * item.units,
                            UnitPrice  = item.unitPrice,
                            ImageUrl32 = imageResolver.GetImageURL(item.typeID)
                        };
                        diccHwd.Add(efth.ItemID, efth);
                    }
                }
            }

            foreach (var item in diccHwd.Values)
            {
                summary.Items.Add(item);
            }
            return(summary);
        }
Exemple #3
0
        public void DeleteGroupList(string userName, string publicID)
        {
            EveShoppingContext contexto = new EveShoppingContext();

            using (TransactionScope scope = new TransactionScope())
            {
                eshGroupShoppingList sl = contexto.eshGroupShoppingLists.Where(s => s.publicID == publicID).FirstOrDefault();
                if (sl == null)
                {
                    throw new ApplicationException(Messages.err_shoppingLisNoExiste);
                }

                if (userName == null)
                {
                    throw new ApplicationException(Messages.err_notOwner);
                }

                UserProfile user = contexto.UserProfiles.Where(u => u.UserName == userName).FirstOrDefault();

                if (sl.userID != 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
                List <eshGroupShoppingListSnapshot> listSnapshots = sl.eshGroupShoppingListSnapshots.ToList();
                foreach (var snp in listSnapshots)
                {
                    contexto.eshGroupShoppingListSnapshots.Remove(snp);
                }
                contexto.eshGroupShoppingLists.Remove(sl);

                contexto.SaveChanges();
                scope.Complete();
            }
        }
Exemple #4
0
 private static void CommonTestGetForGroupShoppingListUpdate(string groupPublicID, string listPublicID, string userName, EveShoppingContext contexto, out eshGroupShoppingList sl)
 {
     CommonTestGetForGroupShoppingListUpdate(groupPublicID, userName, contexto, out sl);
 }
Exemple #5
0
        private static void CommonTestGetForGroupShoppingListUpdate(string groupPublicID, string userName, EveShoppingContext contexto, out eshGroupShoppingList sl)
        {
            sl = contexto.eshGroupShoppingLists.Where(s => s.publicID == groupPublicID).FirstOrDefault();
            if (sl == null)
            {
                throw new ApplicationException(Messages.err_shoppingLisNoExiste);
            }

            if (userName == null)
            {
                throw new ApplicationException(Messages.err_notOwner);
            }

            UserProfile user = contexto.UserProfiles.Where(u => u.UserName == userName).FirstOrDefault();

            if (sl.userID != user.UserId)
            {
                throw new ApplicationException(Messages.err_notOwner);
            }
        }