Exemplo n.º 1
0
        //Save statistic number of visitors into database
        private void CountVisitors()
        {
            //Count 1 for each time user accessing to website
            var listUserAddress = _dbContext.SYS_COUNTER.ToList();

            foreach (var item in listUserAddress)
            {
                if (item.IPAddress.Equals(Request.UserHostAddress) && item.AccessedDate.Date == DateTime.Now.Date)
                {
                    item.AccessedTime += 1;
                    _dbContext.Entry(item).State = EntityState.Modified;
                    _dbContext.SaveChanges();
                    return;
                }

                if (item.IPAddress.Equals("::1"))
                {
                    item.AccessedTime = 0;
                    _dbContext.Entry(item).State = EntityState.Modified;
                    _dbContext.SaveChanges();
                }
            }

            // if ip address and datetime are not existed in database
            SYS_COUNTER counter = new SYS_COUNTER()
            {
                IPAddress = Request.UserHostAddress,
                AccessedDate = DateTime.Now,
                AccessedTime = 1
            };

            _dbContext.SYS_COUNTER.Add(counter);
            _dbContext.SaveChanges();
        }
Exemplo n.º 2
0
        public ActionResult EditNotification(int ID, int TypeID, int LibID, string Title, string Content)
        {
            if (TypeID == 0 && LibID == 0)
            {
                TempData["ErrorUpdateMessage"] = "Vui lòng chọn mục đăng bài và thư viện!";

                return(RedirectToAction("EditNotification", new { noticeId = ID }));
            }

            if (TypeID == 0)
            {
                TempData["ErrorUpdateMessage"] = "Vui lòng chọn mục đăng bài!";

                return(RedirectToAction("EditNotification", new { noticeId = ID }));
            }

            if (LibID == 0)
            {
                TempData["ErrorUpdateMessage"] = "Vui lòng chọn thư viện!";

                return(RedirectToAction("EditNotification", new { noticeId = ID }));
            }

            if (string.IsNullOrEmpty(Title.Trim()))
            {
                TempData["ErrorUpdateMessage"] = "Vui lòng nhập tiêu đề!";

                return(RedirectToAction("EditNotification", new { noticeId = ID }));
            }

            if (string.IsNullOrEmpty(Content.Trim()))
            {
                TempData["ErrorUpdateMessage"] = "Vui lòng nhập nội dung bài viết!";

                return(RedirectToAction("EditNotification", new { noticeId = ID }));
            }

            if (ModelState.IsValid)
            {
                var notice = _dbContext.NOTICE_STORE.FirstOrDefault(t => t.ID == ID);

                if (notice != null)
                {
                    notice.Title      = Title;
                    notice.Content    = Content;
                    notice.TypeID     = TypeID;
                    notice.LibID      = LibID;
                    notice.CreateTime = DateTime.Now;
                }

                _dbContext.Entry(notice).State = EntityState.Modified;
                _dbContext.SaveChanges();
            }

            TempData["UpdateSuccessfulMessage"] = "Cập nhật bài viết thành công!!";
            TempData.Remove("SearchNoticeList");

            return(RedirectToAction("NotificationHome", new { page = 1 }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update password
        /// </summary>
        /// <param name="password"></param>
        /// <param name="userID"></param>
        public void UpdatePassword(string password, int userID)
        {
            using (var dbContext = new OpacEntities())
            {
                var account = (from a in dbContext.CIR_PATRON where a.ID == userID select a).FirstOrDefault();

                if (account != null)
                {
                    account.Password = password;
                    dbContext.Entry(account).State = EntityState.Modified;
                    dbContext.SaveChanges();
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Update extend date and count time of extend date
 /// </summary>
 /// <param name="newDate"></param>
 /// <param name="countRenew"></param>
 /// <param name="ID"></param>
 public void ExtendDate(string newDate, int countRenew, int ID)
 {
     using (var dbContext = new OpacEntities())
     {
         var item = (from t in dbContext.CIR_LOAN where t.ID == ID select t).FirstOrDefault();
         if (item != null)
         {
             var tempDateTime = DateTime.ParseExact(newDate, "dd/MM/yyyy",
                                                    System.Globalization.CultureInfo.InvariantCulture).ToString("yyyy/MM/dd");
             var newDateTime = DateTime.ParseExact(tempDateTime, "yyyy/MM/dd",
                                                   System.Globalization.CultureInfo.InvariantCulture);
             item.DueDate                = newDateTime;
             item.RenewCount             = (short)countRenew;
             dbContext.Entry(item).State = EntityState.Modified;
             dbContext.SaveChanges();
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Update password via Email
        /// </summary>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="studentCode"></param>
        /// <returns></returns>
        public int UpdatePasswordByEmail(string password, string email, string studentCode)
        {
            using (var dbContext = new OpacEntities())
            {
                var account = (from a in dbContext.CIR_PATRON
                               where a.Email.Equals(email) && a.Code.Equals(studentCode)
                               select a).FirstOrDefault();
                if (account != null)
                {
                    account.Password = password;
                    dbContext.Entry(account).State = EntityState.Modified;
                    dbContext.SaveChanges();
                    return(1);
                }
            }

            return(-1);
        }