示例#1
0
 public static async Task <ErrorModel> AddBottles(long inventoryId, string currentAmount, int amount, long shelfId)
 {
     if (char.IsDigit(currentAmount[0]))
     {
         return(await Infrastructure.UpdateInventory(inventoryId, shelfId, int.Parse(currentAmount) + amount));
     }
     else if (!char.IsDigit(currentAmount[0]))
     {
         // return await Infrastructure.AddNewInventory(int.Parse(amount) + 1, shelfId);
     }
     return(new ErrorModel {
         ErrorCode = false, Message = "Någonting gick fel!", Object = null
     });
 }
示例#2
0
        public static async Task <ErrorModel> RemoveBottles(long inventoryId, string currentAmount, int amount, long shelfId)
        {
            if (inventoryId == 0 || string.Equals(currentAmount, "-") || shelfId == 0)
            {
                return new ErrorModel {
                           ErrorCode = false, Message = "Inga flaskor att ta bort!", Object = null
                }
            }
            ;
            var newAmount = int.Parse(currentAmount) - amount;

            if (newAmount < 0)
            {
                return new ErrorModel {
                           ErrorCode = false, Message = "summan blir mindre än noll!", Object = null
                }
            }
            ;

            return(await Infrastructure.UpdateInventory(inventoryId, shelfId, newAmount));
        }
示例#3
0
        private static async Task <ErrorModel> GetWineList(string url, string startsWith, long countryId, long regionId)
        {
            var shelves = await GetUsersShelves();

            var metadetaErrorModel = await Infrastructure.GetMetadata();

            MetaDataResponse metadata = (MetaDataResponse)metadetaErrorModel.Object;

            if (!string.IsNullOrEmpty(startsWith))
            {
                url = url.Replace("startswith=", "startswith=" + startsWith);
            }
            if (countryId > 0)
            {
                url = url.Replace("countryid=-1", "countryid=" + countryId);
            }
            if (regionId > 0)
            {
                url = url.Replace("regionid=-1", "regionid=" + regionId);
            }

            ICollection <WineListResponse> responseBodyJson = new List <WineListResponse>();
            var token = await GetToken();

            var responseErrorModel = await RestVerbs.Get(url, token);

            if (responseErrorModel.ErrorCode)
            {
                responseBodyJson = JsonConvert.DeserializeObject <ICollection <WineListResponse> >((string)responseErrorModel.Object);
            }
            else
            {
                return(responseErrorModel);
            }



            var wineTickets = new List <WineTicket>();

            responseBodyJson = responseBodyJson.Take(10).ToList();
            foreach (var wine in responseBodyJson)
            {
                //List<VintageResponse> vintages = await GetVintages(wine.WineId);

                List <InventoryTicket> inves = new List <InventoryTicket>();
                if (wine.Vintages != null)
                {
                    foreach (var inv in wine.Vintages)
                    {
                        inves.Add(new InventoryTicket(shelves)
                        {
                            Year          = inv != null ? inv.Year : "",
                            CurrentAmount = inv != null ? inv.Amount.ToString() : "",
                            Shelf         = inv.ShelfName,
                            //Grade = (inv.Grade != null && inv.Grade.Grade >= 1 && inv.Grade.Grade <= 5) ? inv.Grade.Grade.ToString() : "-",
                            Grade       = "--",
                            InventoryId = inv.InventoryId,
                            ShelfId     = inv.ShelfId,
                        });
                    }
                }
                else
                {
                    inves.Add(new InventoryTicket(shelves)
                    {
                        CurrentAmount = "-", Year = "-", Grade = "--", Shelf = "-"
                    });
                }

                //string origin = wine.Country.CountryName;
                //// if (wine.Region.RegionName != "Okänt region")
                //origin += " >> \r\n" + wine.Region.RegionName;
                ////  if (wine.District.DistrictName != "Okänt distrikt")
                //origin += " >> \r\n" + wine.District.DistrictName;

                string grapes = "";
                foreach (var grape in wine.WineGrapes)
                {
                    grapes += grape.GrapeName + ((grape.Percent > 0) ? " " + grape.Percent + "%" + "\r\n" : "\r\n");
                }
                wineTickets.Add(new WineTicket(metadata)
                {
                    WineId   = wine.WineId,
                    WineName = wine.WineName,
                    Alcohol  = wine.Alcohol.ToString() + '%',
                    Bottles  = inves,
                    Country  = wine.Country.CountryName,
                    Region   = wine.Region.RegionName,
                    District = wine.District.DistrictName,
                    Producer = wine.Producer,
                    Grapes   = grapes,
                    WinePic  = wine.ImageThumbnail
                });
            }
            return(new ErrorModel {
                ErrorCode = true, Message = null, Object = wineTickets
            });
        }