コード例 #1
0
        public async Task <ExamPeriod> Delete(ExamPeriod examPeriod)
        {
            if (!await ExamPeriodValidator.Delete(examPeriod))
            {
                return(examPeriod);
            }

            using (UOW.Begin())
            {
                try
                {
                    examPeriod = await UOW.ExamPeriodRepository.Get(examPeriod.Id);

                    await UOW.ExamPeriodRepository.Delete(examPeriod.Id);

                    await UOW.Commit();
                }
                catch (Exception e)
                {
                    await UOW.Rollback();

                    examPeriod.AddError(nameof(ExamPeriodService), nameof(Delete), CommonEnum.ErrorCode.SystemError);
                }
            }
            return(examPeriod);
        }
コード例 #2
0
        public async Task <ExamPeriod> Update(ExamPeriod examPeriod)
        {
            if (!await ExamPeriodValidator.Update(examPeriod))
            {
                return(examPeriod);
            }

            using (UOW.Begin())
            {
                try
                {
                    //examPeriod = await GetTermIdExamProgramId(examPeriod);

                    await UOW.ExamPeriodRepository.Update(examPeriod);

                    await UOW.Commit();

                    return(await UOW.ExamPeriodRepository.Get(examPeriod.Id));
                }
                catch (Exception e)
                {
                    await UOW.Rollback();

                    examPeriod.AddError(nameof(ExamPeriodService), nameof(Update), CommonEnum.ErrorCode.SystemError);
                    return(examPeriod);
                }
            }
        }
コード例 #3
0
ファイル: Service.svc.cs プロジェクト: milans17/MasterStudy
        public IEnumerable <ExamPeriod> GetActiveExamPeriods()
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                List <ExamPeriod> examPeriods = new List <ExamPeriod>();

                var activeExamPeriods = dbContext.tblExamPeriods.Where(x => x.IsActive == true);
                var date = DateTime.Now.ToLocalTime();

                foreach (var activeExamPeriod in activeExamPeriods)
                {
                    ExamPeriod ep = new ExamPeriod()
                    {
                        ExamPeriodId = activeExamPeriod.ExamPeriodId,
                        Name         = activeExamPeriod.Name,
                        StartDate    = activeExamPeriod.StartDate,
                        EndDate      = activeExamPeriod.EndDate
                    };

                    examPeriods.Add(ep);
                }

                return(examPeriods);
            }
        }
コード例 #4
0
        /*
         * Lấy danh sách các kì thi từ sql server
         */
        public List <ExamPeriod> GetExamPeriod(out string out_mess)
        {
            List <ExamPeriod> data = new List <ExamPeriod>();

            out_mess = "";
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("SHOW_EXAM_PERIOD", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    var ext = new ExamPeriod
                              (
                        Convert.ToInt32(reader[0]),
                        Convert.ToInt32(reader[1])

                              );
                    data.Add(ext);
                }
            }
            catch (Exception ex)
            {
                out_mess = ex.Message;
                return(null);
            }
            return(data);
        }
コード例 #5
0
        private async Task <bool> ValidateNotExist(ExamPeriod examPeriod)
        {
            ExamPeriodFilter filter = new ExamPeriodFilter
            {
                Take     = Int32.MaxValue,
                ExamDate = new DateTimeFilter {
                    Equal = examPeriod.ExamDate
                },                                                             // Kiểm tra trùng lịch
                StartHour  = examPeriod.StartHour,
                FinishHour = examPeriod.FinishHour,
                TermId     = new GuidFilter {
                    Equal = examPeriod.TermId
                },
                ExamProgramId = new GuidFilter {
                    Equal = examPeriod.ExamProgramId
                }
            };

            int count = await UOW.ExamPeriodRepository.Count(filter);

            if (count > 0)
            {
                examPeriod.AddError(nameof(ExamPeriodValidator), nameof(examPeriod), ERROR.ExamPeriodExisted);
                return(false);
            }
            return(true);
        }
コード例 #6
0
ファイル: Service.svc.cs プロジェクト: milans17/MasterStudy
        public IEnumerable <ExamPeriod> GetAllExamPeriods()
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var dbExamPeriods             = dbContext.tblExamPeriods.ToList();
                List <ExamPeriod> examPeriods = new List <ExamPeriod>(dbExamPeriods.Count);

                foreach (var dbExamPeriod in dbExamPeriods)
                {
                    ExamPeriod examPeriod = new ExamPeriod()
                    {
                        ExamPeriodId = dbExamPeriod.ExamPeriodId,
                        Name         = dbExamPeriod.Name,
                        StartDate    = dbExamPeriod.StartDate,
                        EndDate      = dbExamPeriod.EndDate,
                        SchoolYear   = dbExamPeriod.SchoolYear,
                        IsActive     = dbExamPeriod.IsActive,
                        IsApsolvent  = dbExamPeriod.IsApsolvent
                    };

                    examPeriods.Add(examPeriod);
                }

                return(examPeriods);
            }
        }
コード例 #7
0
        public async Task <ExamPeriodDTO> Create([FromBody] ExamPeriodDTO examPeriodRequestDTO)
        {
            ExamPeriod newExamPeriod = new ExamPeriod
            {
                ExamDate      = DateTime.ParseExact(examPeriodRequestDTO.ExamDate, "dd-MM-yyyy", CultureInfo.InvariantCulture),
                StartHour     = examPeriodRequestDTO.StartHour,
                FinishHour    = examPeriodRequestDTO.FinishHour,
                TermId        = examPeriodRequestDTO.TermId,
                ExamProgramId = examPeriodRequestDTO.ExamProgramId
            };
            ExamPeriod res = await ExamPeriodService.Create(newExamPeriod);

            return(new ExamPeriodDTO
            {
                Id = res.Id,
                ExamDate = res.ExamDate.ToString("dd-MM-yyyy"),
                StartHour = res.StartHour,
                FinishHour = res.FinishHour,
                TermId = res.TermId,
                SubjectName = res.SubjectName,
                ExamProgramId = res.ExamProgramId,
                ExamProgramName = res.ExamProgramName,
                ExamRooms = res.ExamRooms.Select(r => new ExamRoomDTO
                {
                    Id = r.Id,
                    Code = r.Code,
                    RoomNumber = r.RoomNumber,
                    AmphitheaterName = r.AmphitheaterName,
                    ComputerNumber = r.ComputerNumber
                }).ToList(),
                Errors = res.Errors
            });
        }
コード例 #8
0
ファイル: EnumStatus.cs プロジェクト: DatasourceDev/tuexamapi
        public static ExamPeriod toExamPeriod(this string text)
        {
            ExamPeriod str = ExamPeriod.Morning;

            switch (text)
            {
            case "เช้า":
                str = ExamPeriod.Morning;
                break;

            case "บ่าย":
                str = ExamPeriod.Afternoon;
                break;

            case "ค่ำ":
                str = ExamPeriod.Evening;
                break;

            case "0":
                str = ExamPeriod.Morning;
                break;

            case "1":
                str = ExamPeriod.Afternoon;
                break;

            case "2":
                str = ExamPeriod.Evening;
                break;

            default:
                break;
            }
            return(str);
        }
コード例 #9
0
ファイル: Service.svc.cs プロジェクト: milans17/MasterStudy
        public ExamPeriod AddExamPeriod(ExamPeriod newExamPeriod)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var addExamPeriod = new tblExamPeriods()
                {
                    Name        = newExamPeriod.Name,
                    StartDate   = newExamPeriod.StartDate,
                    EndDate     = newExamPeriod.EndDate,
                    SchoolYear  = newExamPeriod.SchoolYear,
                    IsActive    = newExamPeriod.IsActive,
                    IsApsolvent = newExamPeriod.IsApsolvent
                };

                dbContext.tblExamPeriods.Add(addExamPeriod);
                dbContext.SaveChanges();

                var newExamPeriodId = dbContext.tblExamPeriods.SingleOrDefault(x => x.ExamPeriodId == addExamPeriod.ExamPeriodId);

                return(new ExamPeriod()
                {
                    ExamPeriodId = newExamPeriodId.ExamPeriodId,
                    Name = newExamPeriodId.Name,
                    StartDate = newExamPeriodId.StartDate,
                    EndDate = newExamPeriodId.EndDate,
                    SchoolYear = newExamPeriodId.SchoolYear,
                    IsActive = newExamPeriodId.IsActive,
                    IsApsolvent = newExamPeriodId.IsApsolvent
                });
            }
        }
コード例 #10
0
        public async Task <bool> Delete(ExamPeriod examPeriod)
        {
            bool IsValid = true;

            IsValid &= await ValidateId(examPeriod);

            return(IsValid);
        }
コード例 #11
0
        public ActionResult DeleteConfirmed(int id)
        {
            ExamPeriod examPeriod = db.ExamPeriods.Find(id);

            db.ExamPeriods.Remove(examPeriod);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #12
0
        public async Task <bool> Update(ExamPeriod examPeriod)
        {
            bool IsValid = true;

            IsValid &= await ValidateId(examPeriod);

            //IsValid &= ValidateDateTime(examPeriod);
            return(IsValid);
        }
コード例 #13
0
        public async Task <bool> Create(ExamPeriod examPeriod)
        {
            bool IsValid = true;

            IsValid &= await ValidateNotExist(examPeriod);

            IsValid &= ValidateDateTime(examPeriod);
            return(IsValid);
        }
コード例 #14
0
 public ActionResult Delete(int id)
 {
     if (ModelState.IsValid)
     {
         ExamPeriod examPeriod = db.ExamPeriods.Where(x => x.ExamPeriodID == id).FirstOrDefault <ExamPeriod>();
         db.ExamPeriods.Remove(examPeriod);
         db.SaveChanges();
     }
     return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
 }
コード例 #15
0
 public ActionResult Edit([Bind(Include = "ID,PeriodName,StartDate,EndDate")] ExamPeriod examPeriod)
 {
     if (ModelState.IsValid)
     {
         db.Entry(examPeriod).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(examPeriod));
 }
コード例 #16
0
        public ActionResult Create([Bind(Include = "ID,PeriodName,StartDate,EndDate")] ExamPeriod examPeriod)
        {
            if (ModelState.IsValid)
            {
                db.ExamPeriods.Add(examPeriod);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(examPeriod));
        }
コード例 #17
0
 private bool ValidateDateTime(ExamPeriod examPeriod)
 {
     if (examPeriod.StartHour < 0 || examPeriod.StartHour >= 24)
     {
         examPeriod.AddError(nameof(ExamPeriodValidator), nameof(examPeriod.StartHour), ERROR.StartHourInvalid);
         return(false);
     }
     if (examPeriod.FinishHour < 0 || examPeriod.FinishHour >= 24)
     {
         examPeriod.AddError(nameof(ExamPeriodValidator), nameof(examPeriod.FinishHour), ERROR.FinishHourInvalid);
         return(false);
     }
     return(true);
 }
コード例 #18
0
 public ActionResult AddOrEdit(int id = 0)
 {
     if (id == 0)
     {
         var examPeriodVM = new ExamPeriod();
         examPeriodVM.BegginngOfExamPeriod = DateTime.Now;
         examPeriodVM.EndingOfExamPeriod   = DateTime.Now;
         return(View(examPeriodVM));
     }
     else
     {
         return(View(db.ExamPeriods.Where(x => x.ExamPeriodID == id).FirstOrDefault <ExamPeriod>()));
     }
 }
コード例 #19
0
        // GET: ExamPeriods/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ExamPeriod examPeriod = db.ExamPeriods.Find(id);

            if (examPeriod == null)
            {
                return(HttpNotFound());
            }
            return(View(examPeriod));
        }
コード例 #20
0
        private void ExecuteSave(object p)
        {
            try
            {
                if (!ServiceDataProvider.ValidateExamPeriodActivity(StartDate.Value))
                {
                    MessageBox.Show("Active Exam Period already exists in defined period!", "Exam Period Validation",
                                    MessageBoxButton.OK, MessageBoxImage.Warning);

                    return;
                }

                if (editExamPeriod != null)
                {
                    editExamPeriod.Name        = Name;
                    editExamPeriod.StartDate   = StartDate.Value;
                    editExamPeriod.EndDate     = EndDate.Value;
                    editExamPeriod.SchoolYear  = SchoolYear;
                    editExamPeriod.IsActive    = IsActive;
                    editExamPeriod.IsApsolvent = IsApsolvent;

                    ServiceDataProvider.EditExamPeriod(editExamPeriod);
                    eventAggregator.GetEvent <ExamPeriodEvent>().Publish(editExamPeriod);
                }
                else
                {
                    ExamPeriod ep = new ExamPeriod()
                    {
                        Name        = Name,
                        StartDate   = StartDate.Value,
                        EndDate     = EndDate.Value,
                        SchoolYear  = SchoolYear,
                        IsActive    = IsActive,
                        IsApsolvent = IsApsolvent
                    };

                    ServiceDataProvider.AddExamPeriod(ep);
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            finally
            {
                view.Close();
            }
        }
コード例 #21
0
        public AddExamPeriodViewModel(AddExamPeriodView view, ExamPeriod editExamPeriod, IEventAggregator eventAggregator)
        {
            this.editExamPeriod  = editExamPeriod;
            this.view            = view;
            this.eventAggregator = eventAggregator;

            if (editExamPeriod != null)
            {
                Name        = editExamPeriod.Name;
                StartDate   = editExamPeriod.StartDate;
                EndDate     = editExamPeriod.EndDate;
                SchoolYear  = editExamPeriod.SchoolYear;
                IsActive    = editExamPeriod.IsActive;
                IsApsolvent = editExamPeriod.IsApsolvent;
            }
        }
コード例 #22
0
ファイル: Service.svc.cs プロジェクト: milans17/MasterStudy
        public void EditExamPeriod(ExamPeriod editedExamPeriod)
        {
            using (StudentDbEntities dbContext = new StudentDbEntities())
            {
                var dbExamPeriod = dbContext.tblExamPeriods.Find(editedExamPeriod.ExamPeriodId);

                dbExamPeriod.Name        = editedExamPeriod.Name;
                dbExamPeriod.StartDate   = editedExamPeriod.StartDate;
                dbExamPeriod.EndDate     = editedExamPeriod.EndDate;
                dbExamPeriod.SchoolYear  = editedExamPeriod.SchoolYear;
                dbExamPeriod.IsActive    = editedExamPeriod.IsActive;
                dbExamPeriod.IsApsolvent = editedExamPeriod.IsApsolvent;

                dbContext.SaveChanges();
            }
        }
コード例 #23
0
        /*private async Task<bool> ValidateExist(ExamPeriod examPeriod)
         * {
         *  ExamPeriodFilter filter = new ExamPeriodFilter
         *  {
         *      Take = Int32.MaxValue,
         *      ExamDate = new DateTimeFilter { Equal = examPeriod.ExamDate },
         *      StartHour = examPeriod.StartHour,
         *      FinishHour = examPeriod.FinishHour,
         *      TermId = new GuidFilter { Equal = examPeriod.TermId },
         *      ExamProgramId = new GuidFilter { Equal = examPeriod.ExamProgramId }
         *  };
         *
         *  int count = await UOW.ExamPeriodRepository.Count(filter);
         *  if (count == 0)
         *  {
         *      examPeriod.AddError(nameof(ExamPeriodValidator), nameof(examPeriod), ERROR.NotExisted);
         *      return false;
         *  }
         *  return true;
         * }*/
        private async Task <bool> ValidateId(ExamPeriod ExamPeriod)
        {
            ExamPeriodFilter filter = new ExamPeriodFilter
            {
                Id = new GuidFilter {
                    Equal = ExamPeriod.Id
                }
            };
            int count = await UOW.ExamPeriodRepository.Count(filter);

            if (count == 0)
            {
                ExamPeriod.AddError(nameof(ExamPeriodValidator), nameof(ExamPeriod), ERROR.IdNotFound);
            }

            return(count == 1);
        }
コード例 #24
0
        public async Task <bool> Create(ExamPeriod examPeriod)
        {
            ExamPeriodDAO examPeriodDAO = new ExamPeriodDAO()
            {
                Id            = examPeriod.Id,
                ExamDate      = examPeriod.ExamDate,
                StartHour     = examPeriod.StartHour,
                FinishHour    = examPeriod.FinishHour,
                TermId        = examPeriod.TermId,
                ExamProgramId = examPeriod.ExamProgramId
            };
            await examRegContext.ExamPeriod.AddAsync(examPeriodDAO);

            await examRegContext.SaveChangesAsync();

            return(true);
        }
コード例 #25
0
 public ActionResult AddOrEdit(ExamPeriod examPeriod)
 {
     if (ModelState.IsValid)
     {
         if (examPeriod.ExamPeriodID == 0)
         {
             db.ExamPeriods.Add(examPeriod);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(examPeriod).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
     return(View());
 }
コード例 #26
0
        public async Task <bool> Update(ExamPeriod examPeriod)
        {
            // Xoá ExamRegister của ExamRoomExamPeriod của ExamPeriod
            await examRegContext.ExamRegister
            .Where(e => e.ExamPeriodId == examPeriod.Id)
            .DeleteFromQueryAsync();

            await examRegContext.ExamRoomExamPeriod
            .Where(e => e.ExamPeriodId == examPeriod.Id)
            .DeleteFromQueryAsync();

            // Thêm lại ExamRoomExamPeriod
            await examRegContext.ExamRoomExamPeriod.BulkInsertAsync(examPeriod.ExamRooms.Select(e => new ExamRoomExamPeriodDAO
            {
                ExamPeriodId = examPeriod.Id,
                ExamRoomId = e.Id
            }).ToList());

            return(true);
        }
コード例 #27
0
ファイル: EnumStatus.cs プロジェクト: DatasourceDev/tuexamapi
        public static string toExamPeriodName(this ExamPeriod statusType)
        {
            string str = "";

            switch (statusType)
            {
            case ExamPeriod.Morning:
                str = "เช้า";
                break;

            case ExamPeriod.Afternoon:
                str = "บ่าย";
                break;

            case ExamPeriod.Evening:
                str = "ค่ำ";
                break;

            default:
                break;
            }
            return(str);
        }
コード例 #28
0
        public async Task <ExamPeriodDTO> Update([FromBody] ExamPeriodDTO examPeriodRequestDTO)
        {
            ExamPeriod examPeriod = new ExamPeriod
            {
                Id        = examPeriodRequestDTO.Id,
                ExamRooms = examPeriodRequestDTO.ExamRooms.Select(e => new ExamRoom
                {
                    Id               = e.Id,
                    Code             = e.Code,
                    RoomNumber       = e.RoomNumber,
                    AmphitheaterName = e.AmphitheaterName,
                    ComputerNumber   = e.ComputerNumber
                }).ToList()
            };
            ExamPeriod res = await ExamPeriodService.Update(examPeriod);

            return(new ExamPeriodDTO
            {
                Id = res.Id,
                ExamDate = res.ExamDate.ToString("dd-MM-yyyy"),
                StartHour = res.StartHour,
                FinishHour = res.FinishHour,
                TermId = res.TermId,
                SubjectName = res.SubjectName,
                ExamProgramId = res.ExamProgramId,
                ExamProgramName = res.ExamProgramName,
                ExamRooms = res.ExamRooms.Select(r => new ExamRoomDTO
                {
                    Id = r.Id,
                    Code = r.Code,
                    RoomNumber = r.RoomNumber,
                    AmphitheaterName = r.AmphitheaterName,
                    ComputerNumber = r.ComputerNumber
                }).ToList(),
                Errors = res.Errors
            });
        }
コード例 #29
0
 public static void EditExamPeriod(ExamPeriod editEP)
 {
     proxy.EditExamPeriod(editEP);
 }
コード例 #30
0
 public ExamPeriodEventArgs(ExamPeriod examPeriod)
 {
     this.examPeriod = examPeriod;
 }