Exemple #1
0
        public virtual void Insert(TaskViewModel task, ModelStateDictionary modelState)
        {
            if (ValidateModel(task, modelState))
            {
                if (!UpdateDatabase)
                {
                    var first = GetAll().OrderByDescending(e => e.TaskID).FirstOrDefault();
                    var id    = (first != null) ? first.TaskID : 0;

                    task.TaskID = id + 1;

                    GetAll().Insert(0, task);
                }
                else
                {
                    if (string.IsNullOrEmpty(task.Title))
                    {
                        task.Title = "";
                    }

                    var entity = task.ToEntity();

                    db.LichHops.Add(entity);
                    db.SaveChanges();

                    task.TaskID = entity.ID;
                }
            }
        }
Exemple #2
0
        public static void WriteLog(string module, string action, string description)
        {
            try
            {
                NhanVien user = (NhanVien)HttpContext.Current.Session["DangNhap"];
                if (user == null)
                {
                    user             = new NhanVien();
                    user.TenDangNhap = "anonymous";
                }
                using (QuanLyVanBanEntities db = new QuanLyVanBanEntities())
                {
                    NhatKy item = new NhatKy();
                    item.DateTime    = DateTime.Now;
                    item.Module      = module;
                    item.Action      = action;
                    item.Description = description;
                    item.Author      = user.TenDangNhap;
                    item.IpAddress   = GetClientIpAddress();

                    db.NhatKies.Add(item);
                    db.SaveChanges();

                    // SendMail
                    var config = db.CauHinhs.Where(x => x.MaCauHinh == "EMAIL-LOG").FirstOrDefault();
                    if (config != null)
                    {
                        string strEmail = config.DuLieu;
                        if (!string.IsNullOrEmpty(strEmail))
                        {
                            var    tool     = new Tools();
                            string strTitle = db.CauHinhs.Where(x => x.MaCauHinh == "EMAIL-LOG-TITLE").Select(x => x.DuLieu).FirstOrDefault();
                            string strHtml  = db.CauHinhs.Where(x => x.MaCauHinh == "EMAIL-LOG-BODY").Select(x => x.DuLieu).FirstOrDefault();

                            strTitle = strTitle.Replace("{ACTION}", action);
                            strHtml  = strHtml.Replace("{USERNAME}", user.TenDangNhap);
                            strHtml  = strHtml.Replace("{FULLNAME}", user.HoTen);
                            strHtml  = strHtml.Replace("{LOG}", description);

                            tool.SendMail(strHtml, strEmail, strTitle);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }