Example #1
0
        public List<PartyMate> Get(string token)
        {
            var context = new CowabangaContext();

            var tokenEnt = TokenHelper.GetTokenEnt(token, context);

            return tokenEnt.Table.PartyMates;
        }
        public CheckTokenResponse Get(string token)
        {
            var context = new CowabangaContext();

            Guid guid;
            return new CheckTokenResponse()
            {
                Result = Guid.TryParse(token, out guid) && context.AppTokens.Any(x => x.Token == guid)
            };
        }
        public void Post(string token)
        {
            var context = new CowabangaContext();

            var tokenEnt = TokenHelper.GetTokenEnt(token, context);

            foreach (var result in tokenEnt.Table.PartyMates.SelectMany(x=>x.Orders))
            {
                context.Orders.Remove(result);
            }

            context.SaveChanges();

            foreach (var partyMate in tokenEnt.Table.PartyMates)
            {
                context.PartyMates.Remove(partyMate);
            }

            context.SaveChanges();
        }
Example #4
0
        public List<PartyMate> Post(string token, [FromBody]AddPartyMateParams addPartyMateParams)
        {
            var context = new CowabangaContext();

            var tokenEnt = TokenHelper.GetTokenEnt(token, context);

            if (!string.IsNullOrEmpty(addPartyMateParams.VkId))
            {
                if (tokenEnt.Table.PartyMates.Any(x => x.vkId == addPartyMateParams.VkId))
                {
                    throw new ArgumentException();
                }
            }

            var partyMate = new PartyMate() {Name = addPartyMateParams.Name, vkId = addPartyMateParams.VkId, Photo = addPartyMateParams.Photo};
            tokenEnt.Table.PartyMates.Add(partyMate);

            context.SaveChanges();

            return tokenEnt.Table.PartyMates;
        }
        public TokenResponse Post([FromBody]TokenParams tokenParams)
        {
            if (tokenParams.RestarauntId != "3f46ac68-54f4-4ea5-84c1-b7db224a544e")
                NotFound();

            var context = new CowabangaContext();

            var appToken = new AppToken()
            {
                Token = Guid.NewGuid(),
                RestarauntId = tokenParams.RestarauntId,
                TableCode = tokenParams.TableId,
                VKToken = tokenParams.VkId,
                Name = tokenParams.Name,
                Table = new Table() { PartyMates = new List<PartyMate>() { new PartyMate() {Name = tokenParams.Name, vkId = tokenParams.VkId} } }
            };
            context.AppTokens.Add(appToken);

            context.SaveChanges();

            return new TokenResponse() {Token = appToken.Token.ToString()};
        }
Example #6
0
        public List<PartyMate> Post(string token, [FromBody]List<OrderItem> makeOrderParams)
        {
            var context = new CowabangaContext();

            var tokenEnt = TokenHelper.GetTokenEnt(token, context);

            foreach (var item in makeOrderParams.GroupBy(x=>x.PartyMateId))
            {
                var partyMate = tokenEnt.Table.PartyMates.FirstOrDefault(x => x.Id == item.Key);
                if (partyMate != null)
                {
                    partyMate.Orders = new List<Order>();
                    foreach (var orderItem in item)
                    {
                        partyMate.Orders.Add(new Order()
                        {
                            Name = orderItem.Name, ProductId = orderItem.Id, Price = orderItem.Price
                        });
                    }
                }
            }

            var iikoRes = IIKOHelper.MakeOrder(new IIKOMakeOrderParams()
            {
                CustomerToken = tokenEnt.Token.ToString(),
                OrganizationId = tokenEnt.RestarauntId,
                IIKOOrderItems = makeOrderParams.GroupBy(x => x.Id).Select(
                items => new IIKOOrderItem() { Id = items.Key, Name = items.First().Name, Amount = items.Count() }).ToList()
            });

            tokenEnt.IIKOOrderId = iikoRes;

            context.SaveChanges();

            return tokenEnt.Table.PartyMates;
        }