Example #1
0
 public void InsertOrUpdate(RequestInfo requestInfo, bool isInsert)
 {
     if (isInsert) //TODO: try.
     {
         _databaseContext.RequestsInfo.Add(requestInfo);
     }
     else
     {
         _databaseContext.Entry(requestInfo).State = System.Data.Entity.EntityState.Modified;
     }
 }
Example #2
0
        //Добавление строки о новом пользователе в таблицу RequestsInfo.
        public ActionResult CreateRequest()
        {
            //Поиск id для текущего пользователя.
            string userId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            //Old option with SQLite context.
            //SQLiteContext context = new SQLiteContext();

            //string sqlInsert = string.Format(
            //        @"INSERT INTO RequestsInfo(UserId, amountOfQueries, registerDateTime, lastLoginDateTime) VALUES ('{0}', {1}, '{2}', '{3}');"
            //        , userId, 0, DateTime.Now.ToString(CultureInfo.InvariantCulture), DateTime.Now.ToString(CultureInfo.InvariantCulture));

            //context.ExecuteQuery(sqlInsert);

            //Option with DAL layer.
            DALContext _context = new DALContext();
            RequestInfo _requestInfo = new RequestInfo() {UserId = userId, AmountOfQueries = 0
                                        , LastLoginDateTime = DateTime.Now.ToString(CultureInfo.InvariantCulture)
                                        , RegisterDateTime = DateTime.Now.ToString(CultureInfo.InvariantCulture) };
             
            _context.Requests.InsertOrUpdate(_requestInfo, true);
            _context.Requests.Save();

            return RedirectToAction("Index", "Home");
        }