Exemple #1
0
 public ActionResult CreateLeaveForm(TaoDonNghiPhep dnp)
 {
     System.Diagnostics.Debug.WriteLine("CreateLeaveForm CreateLeaveForm CreateLeaveForm ", dnp.reason);
     if (ModelState.IsValid)
     {
         NghiphepEntities db       = new NghiphepEntities();
         Document         document = queryDocument();
         string           code     = CreateAutoCode(document != null ? document.code : null);
         var user = db.Users.FirstOrDefault(x => x.username == User.Identity.Name);
         var doc  = new Document()
         {
             C_id        = code,
             code        = code,
             status      = 0,
             createdAt   = (float)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             startDate   = (float)(DateTime.ParseExact(dnp.dateStart, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             endDate     = (float)(DateTime.ParseExact(dnp.dateEnd, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             createdById = user.C_id,
             reason      = dnp.reason
         };
         db.Documents.Add(doc);
         //try
         //{
         db.SaveChanges();
         //}
         //catch (DbEntityValidationException e)
         //{
         //    foreach (var eve in e.EntityValidationErrors)
         //    {
         //        System.Diagnostics.Debug.WriteLine(eve.Entry.Entity.GetType().Name, eve.Entry.State);
         //        foreach (var ve in eve.ValidationErrors)
         //        {
         //            System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
         //                ve.PropertyName, ve.ErrorMessage);
         //        }
         //    }
         //}
         //write code to update student
         //Gửi mail khi tạo đơn, tương tự bên dưới luôn (CancelDocument)
         string mailBody = "Xin chào: " + user.fullName + "<br>"
                           + "Thông tin đơn nghỉ phép của bạn đang chờ duyệt: <br>"
                           + "- Từ ngày: " + dnp.dateStart + "<br>"
                           + "- Đến ngày: " + dnp.dateEnd + "<br>"
                           + "- Lý do: " + dnp.reason + "<br>"
                           + "Xin cảm ơn.";
         var mail = new MailModel
         {
             ListToEmail = new List <string> {
                 user.email
             },
             Body         = mailBody,
             EmailSubject = "Thông tin đơn xin nghỉ phép"
         };
         EmailHelper.SendMail(mail);
         return(RedirectToAction("Employee"));
     }
     return(RedirectToAction("CreateNew"));
 }
Exemple #2
0
 public ActionResult CreateLeaveForm(TaoDonNghiPhep dnp)
 {
     System.Diagnostics.Debug.WriteLine("CreateLeaveForm CreateLeaveForm CreateLeaveForm ", dnp.reason);
     if (ModelState.IsValid)
     {
         NghiphepEntities db       = new NghiphepEntities();
         Document         document = queryDocument();
         string           code     = CreateAutoCode(document != null ? document.code : null);
         db.Documents.Add(new Document()
         {
             C_id        = code,
             code        = code,
             status      = 0,
             createdAt   = (float)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             startDate   = (float)(DateTime.ParseExact(dnp.dateStart, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             endDate     = (float)(DateTime.ParseExact(dnp.dateEnd, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             createdById = "USER_002",
             reason      = dnp.reason
         });
         //try
         //{
         db.SaveChanges();
         //}
         //catch (DbEntityValidationException e)
         //{
         //    foreach (var eve in e.EntityValidationErrors)
         //    {
         //        System.Diagnostics.Debug.WriteLine(eve.Entry.Entity.GetType().Name, eve.Entry.State);
         //        foreach (var ve in eve.ValidationErrors)
         //        {
         //            System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
         //                ve.PropertyName, ve.ErrorMessage);
         //        }
         //    }
         //}
         //write code to update student
         return(RedirectToAction("Employee"));
     }
     return(RedirectToAction("CreateNew"));
 }
Exemple #3
0
 public ActionResult CreateLeaveForm(TaoDonNghiPhep dnp)
 {
     System.Diagnostics.Debug.WriteLine("CreateLeaveForm CreateLeaveForm CreateLeaveForm");
     if (ModelState.IsValid)
     {
         NghiphepEntities db       = new NghiphepEntities();
         Document         document = queryDocument();
         string           code     = CreateAutoCode(document.code);
         db.Documents.Add(new Document()
         {
             C_id        = code,
             code        = code,
             status      = 0,
             createdAt   = (float)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             startDate   = (float)(DateTime.ParseExact(dnp.dateStart, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             endDate     = (float)(DateTime.ParseExact(dnp.dateEnd, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture).Subtract(new DateTime(1970, 1, 1))).TotalSeconds * 1000,
             createdById = "USER_002"
         });
         db.SaveChanges();
         //write code to update student
         return(RedirectToAction("Index"));
     }
     return(RedirectToAction("CreateNew"));
 }