Esempio n. 1
0
        public async Task <Vehicle> Add(string manufacturer, string model, decimal engine, int horsePower, string description, User owner)
        {
            if (String.IsNullOrEmpty(manufacturer) ||
                String.IsNullOrEmpty(model) ||
                engine == 0.0M ||
                horsePower == 0)
            {
                throw new Exception("Brakujące dane! Wypełnij wszystkie pola");
            }

            if (manufacturer.Length > 32)
            {
                throw new Exception("Nazwa producenta jest za długa!");
            }

            if (model.Length > 32)
            {
                throw new Exception("Nazwa modelu jest za długa!");
            }

            var result = await _ctx.Vehicles.AddAsync(new Vehicle()
            {
                Manufacturer = manufacturer,
                Model        = model,
                Engine       = engine,
                Horsepower   = horsePower,
                Description  = description,
                Owner        = owner
            });

            await _ctx.SaveChangesAsync();

            return(result.Entity);
        }
Esempio n. 2
0
        public async Task <int> VerifyUser(int id, string verificationCode)
        {
            User user = await _ctx.Users.FirstOrDefaultAsync(user => user.ID == id);

            if (user == null)
            {
                return(0);
            }

            if (user.VerificationCode != "0" && user.VerificationCode == verificationCode)
            {
                user.VerificationCode = "0";
                _ctx.Users.Update(user);
            }

            return(await _ctx.SaveChangesAsync());
        }
Esempio n. 3
0
        public async Task <int> Delete(Refuel refuel)
        {
            _ctx.Refuels.Remove(refuel);

            return(await _ctx.SaveChangesAsync());
        }