예제 #1
0
        public JsonResult SaveArticle(List <t_article> data)
        {
            DateTime Now = DateTime.Now;

            t_article _article = new t_article();

            _article.create_date           = Now;
            _article.article_id            = 0;
            _article.article_name          = data[0].article_name;
            _article.article_category      = data[0].article_category;
            _article.image                 = data[0].image;
            _article.is_active             = data[0].is_active;
            _article.article_content_short = data[0].article_content_short;
            _article.article_content       = data[0].article_content;
            _article.language              = data[0].language;
            _article.valid_from            = data[0].valid_from;
            _article.valid_to              = data[0].valid_to;
            _article.author                = data[0].author;

            db.t_article.Add(_article);

            db.SaveChanges();

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public string DeleteCustomer(int customerId)
        {
            try
            {
                using (var context = new BAEntities())
                {
                    var customerToDelete = (from cust in context.Contacts.OfType <Customer>()
                                            .Include("Reservations")
                                            where cust.ContactID == customerId
                                            select cust).Single();

                    var reservationsToDelete = customerToDelete.Reservations.ToList();

                    foreach (Reservation r in reservationsToDelete)
                    {
                        context.DeleteObject(r);
                    }

                    context.DeleteObject(customerToDelete);
                    context.SaveChanges();
                    return("Success");
                }
            }
            catch (Exception ex)
            {
                string errorMessage = null;
                //TODO: construct a message to return to the client
                return(errorMessage);
            }
        }
예제 #3
0
        public string InsertCustomer(BAGA.Customer cust)
        {
            if (cust.CustomerTypeID == 0)
            {
                cust.CustomerTypeID = 1;
            }

            cust.AddDate = DateTime.Now.AddYears(-1);
            try
            {
                using (var context = new BAEntities())
                {
                    RemoveTripsFromGraph(cust);
                    context.Contacts.AddObject(cust);
                    context.SaveChanges();
                }
                return(cust.ContactID.ToString());
            }
            catch (Exception ex)
            {
                string errorMessage = null;
                //TODO: construct a message to return to the client
                return(errorMessage);
            }
        }
예제 #4
0
        static void TestDynamicGraphCreation()
        {
            Reservation res;

            using (var context = new BAEntities())
            {
                //test by querying for a reservation then dynamically creating a new payment
                //adding the payment to the reservation and finally saving the changes
                //the AddChildtoParentObject has no understanding of the model or classes
                //that it is wroking with.
                var query = context.Reservations;
                query.MergeOption = MergeOption.NoTracking;
                res = query.OrderBy("it.ReservationID").Skip(1).FirstOrDefault();
                var kvpParent = new KeyValuePair <string, int>("ReservationID", res.ReservationID);
                KeyValuePair <string, object>[] kvpChildValues =
                {
                    new KeyValuePair <string, object>("PaymentDate", DateTime.Now),
                    new KeyValuePair <string, object>("Amount",      (Decimal)400)
                };
                if (AddChildtoParentObject <Reservation, Payment>
                        (context, kvpParent, kvpChildValues))
                {
                    context.SaveChanges();
                }
            }
        }
 public void SaveChanges()
 {
     lock (_context)
     {
         _context.SaveChanges();
     }
 }
예제 #6
0
 public bool SaveChanges(out string messages)
 {
     if (!PreSavingValidate(out messages))
     {
         return(false);
     }
     _context.SaveChanges();
     return(true);
 }
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     if (validateNewTrips())
     {
         context.SaveChanges();
     }
     else
     {
         MessageBox.Show("Changes not saved. You have one or more new trips that are not valid.");
     }
 }
예제 #8
0
 private static void InsertContactToTestSaveChangesCustomization()
 {
     using (var context = new BAEntities())
     {
         var contact  = Contact.CreateContact("Funny", "Name-Here");
         var customer = new Customer();
         customer.Contact = contact;
         context.Customers.AddObject(customer);
         context.SaveChanges();
     }
 }
        public JsonResult SaveBets(List <BETMASTER> data)
        {
            DateTime Now = DateTime.Now;


            t_bet_master _betmaster = new t_bet_master();

            _betmaster.create_date = Now;
            _betmaster.id          = 0;
            _betmaster.bet_name    = data[0].bet_name;
            _betmaster.is_active   = data[0].is_active;
            _betmaster.description = data[0].description;

            db.t_bet_master.Add(_betmaster);

            int BetId = _betmaster.id;


            List <BETDETAIL> bet_details = data[0].BETDETAIL;

            foreach (BETDETAIL obj in bet_details)
            {
                string GameDay = (obj.game_date.ToString("dd"));

                string GameDayName = (obj.game_date.ToString("dddd",
                                                             new CultureInfo("tr-TR")));

                string GameMonth = (obj.game_date.ToString("MMMM",
                                                           new CultureInfo("tr-TR")));

                string FullGameDay = GameDay + " " + GameMonth + ", " + GameDayName;


                t_bet_detail _betdetail = new t_bet_detail();
                _betdetail.bet_id           = BetId;
                _betdetail.preference       = obj.preference;
                _betdetail.trust            = obj.trust;
                _betdetail.ratio            = obj.ratio;
                _betdetail.possibility      = obj.possibility;
                _betdetail.game_code        = obj.game_code;
                _betdetail.game_name        = obj.game_name;
                _betdetail.game_date        = obj.game_date;
                _betdetail.game_date_prompt = FullGameDay;


                db.t_bet_detail.Add(_betdetail);
            }

            db.SaveChanges();

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
예제 #10
0
        public JsonResult SaveContact(List <t_contacts> data)
        {
            DateTime Now = DateTime.Now;

            t_contacts _contacts = new t_contacts();

            _contacts.create_date = Now;
            _contacts.name        = data[0].name;
            _contacts.email       = data[0].email;
            _contacts.comment     = data[0].comment;
            _contacts.login_ip    = data[0].login_ip;

            db.t_contacts.Add(_contacts);

            db.SaveChanges();

            return(Json(true, JsonRequestBehavior.AllowGet));
        }
예제 #11
0
        public string UpdateCustomer(CustomerUpdate customerUpdate)
        {
            try
            {
                var modifiedCustomer = customerUpdate.Customer;
                using (var context = new BAEntities())
                {
                    RemoveTripsFromGraph(modifiedCustomer);
                    context.Contacts.Attach(modifiedCustomer);
                    context.ObjectStateManager.ChangeObjectState(modifiedCustomer, EntityState.Modified);
                    //Code for Existing and New Reservations will go here;
                    context.ContextOptions.LazyLoadingEnabled = false;
                    foreach (var res in modifiedCustomer.Reservations)
                    {
                        if (res.ReservationID > 0)
                        {
                            context.ObjectStateManager.ChangeObjectState(res, EntityState.Modified);
                        }
                        else
                        {
                            context.ObjectStateManager.ChangeObjectState(res, EntityState.Added);
                        }
                    }
                    context.ContextOptions.LazyLoadingEnabled = true;
                    //Code for Deleted Reservations will go here;
                    List <int> deleteResIDs = customerUpdate.ReservationsToDelete;

                    DeleteReservations(context, deleteResIDs);

                    context.SaveChanges();
                }
                return("Success");
            }
            catch (Exception ex)
            {
                return("Error: " + ex.Message);
            }
        }
예제 #12
0
        public JsonResult SaveGames(List <RootObject> data)
        {
            DateTime Now = DateTime.Now;

            string GameDayNamePrompt = (data[0].game_date.ToString("dddd",
                                                                   new CultureInfo("en-EN")));

            string GameDay = (data[0].game_date.ToString("dd"));

            string GameDayName = (data[0].game_date.ToString("dddd",
                                                             new CultureInfo("tr-TR")));

            string GameMonth = (data[0].game_date.ToString("MMMM",
                                                           new CultureInfo("tr-TR")));

            string FullGameDay = GameDay + " " + GameMonth + ", " + GameDayName;

            ////////////// SET GAME PREFERENCE //////////////////


            List <GAMEDETAIL> game_details = data[0].GAMEDETAIL;

            int    maxPossibility   = int.MinValue;
            string DetailPreference = "";

            foreach (GAMEDETAIL type in game_details)
            {
                int prefDetail = Convert.ToInt32(type.possibility);
                if (prefDetail > maxPossibility)
                {
                    maxPossibility = prefDetail;
                }
            }

            foreach (GAMEDETAIL obj in game_details)
            {
                if (obj.possibility == Convert.ToString(maxPossibility))
                {
                    DetailPreference = obj.preference;
                }
            }
            //////////////////////////////////////////////////////


            t_game_master _gamemaster = new t_game_master();

            _gamemaster.create_date     = Now;
            _gamemaster.id              = 0;
            _gamemaster.game_name       = data[0].game_name;
            _gamemaster.image           = data[0].image;
            _gamemaster.is_active       = data[0].is_active;
            _gamemaster.category        = data[0].category;
            _gamemaster.sub_category    = data[0].sub_category;
            _gamemaster.description     = data[0].description;
            _gamemaster.priority        = data[0].priority;
            _gamemaster.game_date       = data[0].game_date;
            _gamemaster.game_day_prompt = GameDayNamePrompt;
            _gamemaster.game_day        = FullGameDay;
            _gamemaster.game_preference = DetailPreference + " - " + Convert.ToString(maxPossibility);

            db.t_game_master.Add(_gamemaster);

            int GameId = _gamemaster.id;



            foreach (GAMEDETAIL obj in game_details)
            {
                t_game_detail _gamedetail = new t_game_detail();
                _gamedetail.game_id     = GameId;
                _gamedetail.preference  = obj.preference;
                _gamedetail.trust       = obj.trust;
                _gamedetail.ratio       = obj.ratio;
                _gamedetail.possibility = obj.possibility;
                _gamedetail.region      = obj.region;
                _gamedetail.game_code   = obj.game_code;


                db.t_game_detail.Add(_gamedetail);
            }

            db.SaveChanges();

            return(Json(true, JsonRequestBehavior.AllowGet));
        }