Example #1
0
        public async Task <UserVM> CreateUserAsync(UserVM user)
        {
            try
            {
                var newUser = new User()
                {
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    Email     = user.Email
                };

                _ctx.Users.Add(newUser);

                var cellar = new Cellar()
                {
                    Description = user.LastName + "'s Cellar"
                };

                _ctx.Cellars.Add(cellar);

                await _ctx.SaveChangesAsync();

                user.Id = newUser.Id;
                user.CreatedDateTime = newUser.CreatedDateTime;

                return(user);
            }
            catch
            {
                throw;
            }
        }
Example #2
0
        public async Task <BottleType> AddBottleType(CreateBottleTypeVM bottleType)
        {
            try
            {
                var newBottleType = new BottleType()
                {
                    Color              = bottleType.Color,
                    YearVintage        = bottleType.YearVintage,
                    Winery             = bottleType.Winery,
                    Varietal           = bottleType.Varietal,
                    Vinyard            = bottleType.Vinyard,
                    Name               = bottleType.Name,
                    PurchaseDate       = bottleType.PurchaseDate,
                    PurchasePrice      = bottleType.PurchasePrice,
                    StorageDate        = bottleType.StorageDate,
                    StorageTemparature = bottleType.StorageTemparature,
                    CreatedById        = bottleType.CreatedById,
                    OpenedDate         = bottleType.OpenedDate,
                    Notes              = bottleType.Notes
                };

                for (var i = 0; i < bottleType.NewBottleCount; i++)
                {
                    var newBottle = new Bottle()
                    {
                        Color              = bottleType.Color,
                        YearVintage        = bottleType.YearVintage,
                        Winery             = bottleType.Winery,
                        Varietal           = bottleType.Varietal,
                        Vinyard            = bottleType.Vinyard,
                        Name               = bottleType.Name,
                        PurchaseDate       = bottleType.PurchaseDate,
                        PurchasePrice      = bottleType.PurchasePrice,
                        StorageDate        = bottleType.StorageDate,
                        StorageTemparature = bottleType.StorageTemparature,
                        CreatedById        = bottleType.CreatedById,
                        CreatedDateTime    = bottleType.CreatedDateTime,
                        OpenedDate         = bottleType.OpenedDate,
                        Notes              = bottleType.Notes
                    };

                    newBottleType.Bottles.Add(newBottle);
                }

                _ctx.BottleTypes.Add(newBottleType);

                await _ctx.SaveChangesAsync();

                return(newBottleType);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public async Task <CellarVM> CreateCellarAsync(CellarVM newCellar)
        {
            try
            {
                var cellar = new Cellar()
                {
                    Description = newCellar.Description
                };

                await _ctx.Cellars.AddAsync(cellar);

                await _ctx.SaveChangesAsync();

                newCellar.Id = cellar.Id;

                return(newCellar);
            }
            catch
            {
                throw;
            }
        }