コード例 #1
0
        public async Task <int> addAsync(SubscriberModel subsciberModel, float height)
        {
            try
            {
                var exists = await _context.Subscribers.FirstOrDefaultAsync(s => s.email == subsciberModel.email);

                if (exists == null)
                {
                    //SubscriberEntity newSunscriber = _mapper.Map<SubscriberEntity>(subsciber);
                    //await _weightWatchersContext.AddAsync(newSunscriber);
                    subsciberModel.id = Guid.NewGuid();
                    Subscriber s = _mapper.Map <Subscriber>(subsciberModel);
                    await _context.Subscribers.AddAsync(s);

                    await _context.Cards.AddAsync(new Card()
                    {
                        BMI          = 0,
                        subscriberId = subsciberModel.id,
                        height       = height,
                        openDate     = DateTime.Today
                    });

                    return(await _context.SaveChangesAsync());
                }
            }
            catch (Exception e)
            {
                throw new Exception("register failed");
            }
            return(-1);
        }
コード例 #2
0
        public async Task <int> AddAsync(SubscriberModel subsciberModel, float height)
        {
            try
            {
                subsciberModel.id = Guid.NewGuid();
                Subscriber s = _mapper.Map <Subscriber>(subsciberModel);
                await _context.Subscribers.AddAsync(s);

                await _context.Cards.AddAsync(new Card()
                {
                    BMI          = 0,
                    subscriberId = subsciberModel.id,
                    height       = height,
                    openDate     = DateTime.Today
                });

                return(await _context.SaveChangesAsync());
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }