public static DailyNote GetDailyNote(int ForUserID,DateTime forDate)
 {
     DailyNote DailyNote = null;
     DataTable dtDailyNotes = SQLWrapper.GetDataTable(new SelectQueryData { TableName = "CMN_DailyNotes", FilterCondition = "UserID = " + ForUserID.ToString() + " And ForDate = '" + forDate.ToString(Constants.DATE_FORMAT_SQL) +"'" });
     if (dtDailyNotes.Rows.Count > 0)
     {
         DailyNote = loadDailyNote(dtDailyNotes, 0);
     }
     else
     {
         DailyNote = new DailyNote { DailyNoteID = 0, ForDate = forDate, ForUser = DALAppUser.GetUserByID(ForUserID), Notes = "" };
     }
     return DailyNote;
 }
        public static bool DeleteDailyNote(DailyNote dailyNote)
        {
            bool returnValue = false;

            List<IBaseQueryData> queryDatum = new List<IBaseQueryData>();

            DeleteQueryData queryData =  new DeleteQueryData();
            queryData.TableName = "CMN_DailyNotes";
            queryData.KeyFields.Add(new FieldData { FieldName = "ForDate", FieldType = SqlDbType.Date, FieldValue = dailyNote.ForDate.ToString(Constants.DATE_FORMAT_SQL) });
            queryData.KeyFields.Add(new FieldData { FieldName = "UserId", FieldType = SqlDbType.Int, FieldValue = dailyNote.ForUser.UserID.ToString() });
            queryDatum.Add(queryData);

            returnValue = SQLWrapper.ExecuteQuery(queryDatum);

            return returnValue;
        }
 public static bool UpdateDailyNote(DailyNote dailyNote)
 {
     bool returnValue = false;
     DailyNote dn = DALDailyNotes.GetDailyNote(dailyNote.ForUser.UserID, dailyNote.ForDate);
     if (dn != null)
     {
         dn.Notes = dailyNote.Notes;
         returnValue = DALDailyNotes.UpdateDailyNote(dn);
     }
     else
     {
         dn = dailyNote;
         returnValue = DALDailyNotes.AddDailyNote(dn);
     }
     return returnValue;
 }
        public IActionResult AddDailyNote(int id, [Bind("Description")] DailyNote dailyNote)
        {
            var userId  = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var student = _context.Students.Where(s => s.Id == id).FirstOrDefault();

            dailyNote.StudentId   = student.Id;
            dailyNote.Date        = DateTime.Now.Date;
            dailyNote.Description = dailyNote.Description;

            if (dailyNote != null)
            {
                _context.DailyNotes.Add(dailyNote);
            }

            _context.SaveChanges();
            return(RedirectToAction(nameof(SelectedStudent), new { id }));
        }
        public static bool AddDailyNote(DailyNote dailyNote)
        {
            bool returnValue = false;

            int dailyNoteID = getNextDailyNoteID();

            List<IBaseQueryData> queryDatum = new List<IBaseQueryData>();

            IBaseQueryData queryData = new InsertQueryData();
            queryData.TableName = "CMN_DailyNotes";
            queryData.Fields.Add(new FieldData { FieldName = "DailyNoteID", FieldType = SqlDbType.Int, FieldValue = dailyNoteID.ToString() });
            queryData.Fields.Add(new FieldData { FieldName = "DailyNote", FieldType = SqlDbType.NVarChar, FieldValue = dailyNote.Notes.Trim() });
            queryData.Fields.Add(new FieldData { FieldName = "ForDate", FieldType = SqlDbType.Date, FieldValue = dailyNote.ForDate.ToString(Constants.DATE_FORMAT_SQL) });
            queryData.Fields.Add(new FieldData { FieldName = "UserId", FieldType = SqlDbType.Int, FieldValue = dailyNote.ForUser.UserID.ToString() });
            queryDatum.Add(queryData);

            returnValue = SQLWrapper.ExecuteQuery(queryDatum);

            return returnValue;
        }
 private static DailyNote loadDailyNote(DataTable dtDailyNotes, int RowNo)
 {
     DailyNote dailyNote = new DailyNote();
     dailyNote.DailyNoteID = Convert.ToInt32(dtDailyNotes.Rows[RowNo]["DailyNoteID"]);
     dailyNote.Notes = dtDailyNotes.Rows[RowNo]["DailyNote"].ToString();
     dailyNote.ForDate = Convert.ToDateTime(dtDailyNotes.Rows[RowNo]["ForDate"]);
     dailyNote.ForUser = DALAppUser.GetUserByID(Convert.ToInt32(dtDailyNotes.Rows[RowNo]["UserID"]));
     return dailyNote;
 }
 public static bool DeleteDailyNote(DailyNote dailyNote)
 {
     return DALDailyNotes.DeleteDailyNote(dailyNote);
 }
Exemple #8
0
 public bool UpdateDailyNote(DailyNote dn)
 {
     throw new NotImplementedException();
 }
Exemple #9
0
        public ActionResult Create(DailyReportVM drVM, string SubmitButton)
        {
            // check why model state is false
            var errors = ModelState
                         .Where(x => x.Value.Errors.Count > 0)
                         .Select(x => new { x.Key, x.Value.Errors })
                         .ToArray();

            if (ModelState.IsValid)
            {
                drVM.ReportDate = drVM.ReportDate != null ? drVM.ReportDate : DateTime.Today.Date;
                switch (SubmitButton)
                {
                case "بحث":

                    return(RedirectToAction("Create", new { currentReportdate = drVM.ReportDate }));


                case "اضافة":

                    if (drVM.BaseNumber == 0)
                    {
                        TempData["message"] = NotificationSystem.AddMessage("لا يوجد ضباط ", NotificationType.Danger.Value);
                        return(View(drVM));
                    }
                    // daily report

                    /// check if report exist today cz Report Date only inserted one time
                    DailyReport dr_today = _context.DailyReports.Where(t => t.TournamentId == drVM.TournamentId &&
                                                                       (drVM.ReportDate.Date == t.ReportDate.Date)).FirstOrDefault();
                    if (dr_today == null)
                    {
                        DailyReport dr = new DailyReport()
                        {
                            TournamentId   = drVM.TournamentId,
                            IsActive       = true,
                            CreationDate   = DateTime.Today.Date,
                            ReportDate     = drVM.ReportDate,
                            BaseNumber     = drVM.BaseNumber,
                            ReadyNumber    = drVM.ReadyNumber,
                            NotReadyNumber = drVM.NotReadyNumber
                        };
                        _context.DailyReports.Add(dr);
                    }
                    else
                    {
                        dr_today.ReadyNumber    = drVM.ReadyNumber;
                        dr_today.NotReadyNumber = dr_today.NotReadyNumber;
                        _context.DailyReports.Update(dr_today);
                    }

                    // count of incidents already in database and today
                    int counttodayincidents = 0;
                    // loop in old record incidents
                    if (drVM.TodayDailyIncidents != null && drVM.TodayDailyIncidents.Count > 0)
                    {
                        counttodayincidents = drVM.TodayDailyIncidents.Count;
                        foreach (var item in drVM.TodayDailyIncidents)
                        {
                            // find existed daily incident
                            DailyIncident di = _context.DailyIncidents.Find(item.Id);

                            // if the daily incident of officer is finished , we need to update enddate to today
                            if (item.IsFinish)
                            {
                                if (di == null)
                                {
                                    TempData["message"] = NotificationSystem.AddMessage("حصل خطأ في احد وقوعات الضباط ", NotificationType.Danger.Value);
                                    return(View(drVM));
                                }
                                // count day between start date and report date ,  cz when i finish some incident  enddate updated to current report date
                                int countdaybetween = GetCountdaysBetween((DateTime?)item.StartDate, (DateTime?)drVM.ReportDate);

                                // this incident will finish in current date posted
                                di.EndDate             = drVM.ReportDate;
                                di.CountDaysOfIncident = countdaybetween;
                            }
                            di.Explanation = item.Explanation;
                            _context.DailyIncidents.Update(di);

                            //di.ReasonOfIncidentId = item.ReasonOfIncidentId;
                        }
                    }


                    // loop in Daily Notes
                    int CountDailyNotePosted = 0;
                    if (drVM.DailyNotes != null)
                    {
                        foreach (var item in drVM.DailyNotes)
                        {
                            if (item.OfficerId != null || !String.IsNullOrEmpty(item.Note))
                            {
                                DailyNote dn = new DailyNote()
                                {
                                    CreationDate = drVM.ReportDate,
                                    OfficerId    = item.OfficerId,
                                    Note         = item.Note,
                                    IsActive     = true,
                                    IsImportant  = item.IsImportant,
                                    IsPositive   = item.IsPositive,
                                    TournamentId = drVM.TournamentId
                                };
                                CountDailyNotePosted++;
                                _context.DailyNotes.Add(dn);
                            }
                        }
                    }

                    drVM.CountDailyNotePosted = CountDailyNotePosted;



                    // take the records needed from Basenumber record
                    if (drVM.NotReadyNumber - counttodayincidents > 0)
                    {
                        drVM.DailyIncidents = drVM.DailyIncidents.Take(drVM.NotReadyNumber - counttodayincidents).ToList();
                        // loop in new Inserted Record of Daily Incident
                        foreach (var item in drVM.DailyIncidents)
                        {
                            if (item.OfficerId != null)
                            {
                                if (item.EndDate >= item.StartDate)
                                {
                                    int           countdaybetween = GetCountdaysBetween((DateTime?)item.StartDate, (DateTime?)item.EndDate);
                                    DailyIncident di = new DailyIncident()
                                    {
                                        CreationDate        = DateTime.Today,
                                        ReasonOfIncidentId  = item.ReasonOfIncidentId,
                                        Explanation         = item.Explanation,
                                        StartDate           = item.StartDate.Value.Date,
                                        EndDate             = item.EndDate.Value.Date,
                                        IsActive            = true,
                                        OfficerId           = item.OfficerId,
                                        CountDaysOfIncident = countdaybetween,
                                        TournamentId        = drVM.TournamentId
                                    };
                                    _context.DailyIncidents.Add(di);
                                }
                                else
                                {
                                    // if an error exist , i need to call ddlreson cz each user has reson so id need ddlreason data
                                    drVM.DDLReason      = new SelectList(_context.ReasonOfIncidents.ToList().OrderBy(n => n.Name), "Id", "Name");
                                    TempData["message"] = NotificationSystem.AddMessage("يجب التأكد من التاريخ    ", NotificationType.Danger.Value);
                                    return(View(drVM));
                                }
                            }
                            else
                            {
                                // if an error exist , i need to call ddlreson cz each user has reson so id need ddlreason data
                                drVM.DDLReason      = new SelectList(_context.ReasonOfIncidents.ToList().OrderBy(n => n.Name), "Id", "Name");
                                TempData["message"] = NotificationSystem.AddMessage("يوجد وقوعات دون ضابط ", NotificationType.Danger.Value);
                                return(View(drVM));
                            }
                        }
                    }



                    _context.SaveChanges();
                    TempData["message"] = NotificationSystem.AddMessage("تم اضافة التقرير اليومي بنجاح", NotificationType.Success.Value);
                    return(RedirectToAction("Index", new { currentreportdate = drVM.ReportDate }));
                }
            }
            TempData["message"] = NotificationSystem.AddMessage("حصل خطأ ما", NotificationType.Danger.Value);
            return(View(drVM));
        }