public UserEntity UpdateProfile(UserEntity user)
 {
     using var userContext = new LotteryContext();
     userContext.Users.Update(user);
     userContext.SaveChanges();
     return(user);
 }
        public Task Save(UserEntity user)
        {
            using var userContext = new LotteryContext();
            userContext.Users.Add(user);

            userContext.SaveChanges();
            return(Task.CompletedTask);
        }
        public void SavePayment(int id, PaymentEntity paymentEntity)
        {
            using var userContext = new LotteryContext();
            var result = userContext.Users
                         .Include(user => user.Payments)
                         .FirstOrDefault(user => user.Id == id);

            if (result == null)
            {
                throw new Exception("Not found");
            }

            result.Payments.Add(paymentEntity);
            userContext.SaveChanges();
        }
        public void RemovePayment(int id, int paymentId)
        {
            using var userContext = new LotteryContext();
            var result = userContext.Users
                         .Include(user => user.Payments)
                         .FirstOrDefault(user => user.Id == id);

            if (result == null)
            {
                throw new Exception("Not found");
            }

            var payment = result.Payments.FirstOrDefault(p => p.Id == paymentId);

            if (payment == null)
            {
                throw new Exception("Not found");
            }

            result.Payments.Remove(payment);
            userContext.SaveChanges();
        }
Exemple #5
0
        internal void Save(CreateLotteryEventContract contract)
        {
            using var ctx = new LotteryContext();
            var lotteryEvent = new LotteryEventEntity
            {
                Name     = contract.Name,
                DrawDate = contract.DrawDate,
                Price    = contract.Price
            };

            var charities = contract.Charities.Select(c => ctx.CharityEntity.First(entity => entity.Id == c.Id));

            foreach (var c  in charities)
            {
                lotteryEvent.LoteryCharity.Add(new CharityLotteryEntity()
                {
                    Lottery = lotteryEvent,
                    Charity = c
                });
            }
            ctx.LotteryEntity.Add(lotteryEvent);

            ctx.SaveChanges();
        }