示例#1
0
        //Local register
        //Input: registerDTO
        //Output: clientId
        public static string registerClientLocal(registerDTO body)
        {
            SwapDbConnection db     = new SwapDbConnection();
            client           client = db.clients.FirstOrDefault(c => c.email == body.email && (c.platform == "local"));
            string           id     = "";

            if (client == null)
            {
                id = IdService.generateID("client");
                HashSalt hs = HashSalt.GenerateSaltedHash(body.password);

                client new_client = new client()
                {
                    client_id     = id,
                    email         = body.email,
                    birthday_date = body.birthday,
                    creation_date = DateTime.Now,
                    first_name    = body.first_name,
                    last_login    = DateTime.Now,
                    last_name     = body.last_name,
                    phone         = body.phone,
                    sex           = body.sex,
                    password      = hs.Hash,
                    salt          = hs.Salt,
                    platform      = "local"
                };

                db.clients.Add(new_client);
                db.SaveChanges();
            }
            return(id);
        }
示例#2
0
        //add a google_value object to db
        public static google_value AddGoogleValue(string value)
        {
            SwapDbConnection db         = new SwapDbConnection();
            google_value     google_obj = new google_value()
            {
                google_value_id = IdService.generateID("google_value_id"),
                value           = value
            };

            db.google_value.Add(google_obj);
            db.SaveChanges();
            return(google_obj);
        }
示例#3
0
        //Add new product
        //Input: productDTO, ClientId
        //Output: productDTO
        public static productDTO AddProduct(productDTO req, string ClientId)
        {
            SwapDbConnection db       = new SwapDbConnection();
            business         business = db.businesses.FirstOrDefault(b => b.business_owner_id == ClientId && b.place_id == req.business_id);

            if (business == null)
            {
                return(null);
            }
            if (business.products.FirstOrDefault(p => p.name == req.name) != null)
            {
                return(null);
            }

            product product_obj = new product()
            {
                product_id          = IdService.generateID("product_id"),
                creation_date       = DateTime.Now,
                is_active           = req.is_active,
                name                = req.name,
                business_id         = req.business_id,
                discount            = req.discount,
                discount_start_date = req.discount_start_date,
                discount_end_date   = req.discount_end_date,
                price               = req.price,
                description         = req.description
            };

            db.products.Add(product_obj);
            db.SaveChanges();

            return(new productDTO
            {
                business_id = req.business_id,
                creation_date = product_obj.creation_date,
                description = product_obj.description,
                discount = product_obj.discount,
                discount_end_date = product_obj.discount_end_date,
                discount_start_date = product_obj.discount_start_date,
                is_active = product_obj.is_active,
                name = product_obj.name,
                price = product_obj.price,
                product_id = product_obj.product_id
            });
        }
示例#4
0
        //add sub category
        public static sub_category AddSubCategory(string value, string google_value)
        {
            SwapDbConnection db = new SwapDbConnection();

            if (db.sub_category.FirstOrDefault(c => c.name == value && c.google_value == google_value) != null)
            {
                return(null);
            }

            sub_category sub_object = new sub_category()
            {
                sub_id        = IdService.generateID("sub_id"),
                creation_date = DateTime.Now,
                is_active     = false,
                name          = value,
                google_value  = google_value,
            };

            db.sub_category.Add(sub_object);
            db.SaveChanges();
            return(sub_object);
        }
示例#5
0
        //Add new quest
        //Input: QuestDTO
        //Output: void
        public static void AddNewQuest(QuestDTO quest)
        {
            SwapDbConnection db = new SwapDbConnection();
            r_place_sub_and_main_category placeCategories;
            place        place;
            List <place> places;
            quest        newQuest = new quest
            {
                client_id     = quest.userId,
                creation_date = DateTime.Now,
                quest_id      = IdService.generateID("quest_id"),
                places        = new List <place>()
            };

            //Update categories of places
            foreach (GooglePlaceDTO googlePlace in quest.googlePlaces)
            {
                place = db.places.FirstOrDefault(p => p.place_id == googlePlace.googlePlace.place_id);
                if (place != null)
                {
                    placeCategories = place.r_place_sub_and_main_category.FirstOrDefault(p => p.main_id == googlePlace.main_id &&
                                                                                         p.sub_id == googlePlace.sub_id);
                    if (placeCategories == null)
                    {
                        place.r_place_sub_and_main_category.Add(new r_place_sub_and_main_category
                        {
                            creation_date = DateTime.Now,
                            main_id       = googlePlace.main_id,
                            place_id      = googlePlace.googlePlace.place_id,
                            sub_id        = googlePlace.sub_id
                        });
                    }
                }
                //Add new place to db
                else
                {
                    place = new place
                    {
                        latitude      = googlePlace.googlePlace.latitude,
                        place_id      = googlePlace.googlePlace.place_id,
                        longitude     = googlePlace.googlePlace.longitude,
                        country       = googlePlace.googlePlace.country,
                        creation_date = DateTime.Now,
                        description   = googlePlace.googlePlace.description,
                        name          = googlePlace.googlePlace.name,
                        post_code     = googlePlace.googlePlace.post_code,
                        settlement    = googlePlace.googlePlace.settlement,
                        state         = googlePlace.googlePlace.state,
                        street        = googlePlace.googlePlace.street,
                        street_number = googlePlace.googlePlace.street_number,
                        r_place_sub_and_main_category = new List <r_place_sub_and_main_category>
                        {
                            new r_place_sub_and_main_category
                            {
                                creation_date = DateTime.Now,
                                place_id      = googlePlace.googlePlace.place_id,
                                main_id       = googlePlace.main_id,
                                sub_id        = googlePlace.sub_id
                            }
                        }
                    };
                    db.places.Add(place);
                }
                newQuest.places.Add(place);
            }
            places = db.places.Where(p => quest.eventsIds.Contains(p.place_id) ||
                                     quest.businessesIds.Contains(p.place_id)).ToList();
            newQuest.places = newQuest.places.Concat(places).ToList();
            db.quests.Add(newQuest);
            db.SaveChanges();
        }