示例#1
0
        /// <summary>
        /// Registrace nového uživatele
        /// </summary>
        /// <param name="login">Přihlašovací jméno uživatele</param>
        /// <param name="password">Heslo uživatele</param>
        /// <param name="email">Email uživatele</param>
        /// <param name="bornYear">Rok narození uživatele</param>
        /// <param name="regionId">Identifikace regionu, kde uživatel žije</param>
        /// <returns>Objekt <see cref="Response"/>, kde je uložen stav akce a zpráva.</returns>
        /// <exception cref="CarExpensesException">Při chybě aplikace</exception>
        public Response register(string login, string password, string email, int bornYear, int regionId)
        {
            password = MD5(password);
            Response response = new Response(false, "Registration failed.");

            if (bornYear < (DateTime.Today.Year-130) || bornYear > DateTime.Today.Year)
            {
                return new Response(false,"Born year must be between " + (DateTime.Today.Year - 130) + " and " + DateTime.Today.Year + ".");
            }

            if (CarExpensesApp.validateEmail(email) == false)
            {
                return new Response(false, "Email is not in valid format.");
            }

            try
            {
                User user = new User();
                user.login = login;
                user.password = password;
                user.email = email;
                user.bornYear = bornYear;
                user.regionId = regionId;

                if (userDAO.register(user) == true)
                {
                    response.message = "User " + user.login + " was successfuly registered.";
                    response.success = true;
                }
            }
            catch (CarExpensesDatabaseException ex)
            {
                response.success = false;
                response.message = ex.Message.ToString();
            }
            return response;
        }
示例#2
0
        /// <summary>
        /// Přidání nového tankování k aktuálně přihlášenému uživateli
        /// </summary>
        /// <param name="carId">Identifikace auta, do kterého bylo tankováno</param>
        /// <param name="km">Stav tachometru při tankování</param>
        /// <param name="cost">Cena za tankování</param>
        /// <param name="liters">Počet natankovaných litrů paliva</param>
        /// <param name="date">Datum tankování</param>
        /// <returns>Objekt <see cref="Response"/>, kde je uložen stav akce a zpráva.</returns>
        /// <exception cref="CarExpensesException">Při chybě aplikace</exception>
        public Response addGas(int carId, int km, float liters, int cost, DateTime date)
        {
            if (notLogged()) return new Response(false, "You are NOT logged in.");

            if (km < 1 || liters < 1 || cost < 1)
                return new Response(false, "None of values can be smaller than 1.");

            Response response = new Response();
            try
            {
                if (carDAO.userHasCar(user.id, carId) == false)
                {
                    return new Response(false, "User ID " + user.id + " is not owner of car ID " + carId + ".");
                }

                Gas gas = new Gas();
                gas.carId = carId;
                gas.km = km;
                gas.mililiters = (int) Math.Round(liters * 1000);
                gas.cost = cost;
                gas.date = date;

                if (gasDAO.addGas(gas) == true)
                {
                    response.message = "Gas was successfuly added.";
                    response.success = true;
                }
                else
                {
                    response.message = "Gas wasn't added.";
                    response.success = false;
                }
            }
            catch (CarExpensesDatabaseException ex)
            {
                response.success = false;
                response.message = ex.Message.ToString();
            }
            return response;
        }
示例#3
0
        /// <summary>
        /// Přidání nové opravy k aktuálně přihlášenému uživateli
        /// </summary>
        /// <param name="carId">Identifikace auta, které bylo opravováno</param>
        /// <param name="km">Stav tachometru při opravě</param>
        /// <param name="cost">Cena opravy</param>
        /// <param name="serviceTypeId">Identifikace typu opravy</param>
        /// <param name="description">Slovní popis opravy</param>
        /// <param name="date">Datum opravy</param>
        /// <returns>Objekt <see cref="Response"/>, kde je uložen stav akce a zpráva.</returns>
        /// <exception cref="CarExpensesException">Při chybě aplikace</exception>
        public Response addService(int carId, int km, int cost, int serviceTypeId, string description, DateTime date)
        {
            if (notLogged()) return new Response(false, "You are NOT logged in.");

            if (km < 1 || cost < 1)
                return new Response(false, "Km and cost can't be smaller than 1.");

            Response response = new Response();
            try
            {
                if (carDAO.userHasCar(user.id, carId) == false)
                {
                    return new Response(false, "User ID " + user.id + " is not owner of car ID " + carId + ".");
                }

                Service service = new Service();
                service.carId = carId;
                service.km = km;
                service.cost = cost;
                service.serviceTypeId = serviceTypeId;
                service.description = description;
                service.date = date;

                if (serviceDAO.addService(service) == true)
                {
                    response.message = "Service was successfuly added.";
                    response.success = true;
                }
                else
                {
                    response.message = "Service wasn't added.";
                    response.success = false;
                }
            }
            catch (CarExpensesDatabaseException ex)
            {
                response.success = false;
                response.message = ex.Message.ToString();
            }
            return response;
        }
示例#4
0
        /// <summary>
        /// Přidání nového auta k aktuálně přihlášenému uživateli
        /// </summary>
        /// <param name="carModelId">Identifikace typu auta</param>
        /// <param name="name">Jměno auta</param>
        /// <param name="boughtYear">Rok zakoupení auta</param>
        /// <param name="cost">Cena auta</param>
        /// <returns>Objekt <see cref="Response"/>, kde je uložen stav akce a zpráva.</returns>
        /// <exception cref="CarExpensesException">Při chybě aplikace</exception>
        public Response addCar(int carModelId, string name, int boughtYear, int cost)
        {
            if (notLogged()) return new Response(false, "You are NOT logged in.");

            if (boughtYear < 1900 || boughtYear > DateTime.Today.Year)
                return new Response(false, "Bought year must be between " + 1900 + " and " + DateTime.Today.Year + ".");

            Response response = new Response();
            try
            {
                Car car = new Car();
                car.userId = user.id;
                car.carModelId = carModelId;
                car.boughtYear = boughtYear;
                car.cost = cost;
                car.name = name;

                if (carDAO.addCar(car) == true)
                {
                    response.message = "Car was successfuly added.";
                    response.success = true;
                }
            }
            catch (CarExpensesDatabaseException ex)
            {
                response.success = false;
                response.message = ex.Message.ToString();
            }
            return response;
        }