Example #1
0
        public StatusModel Update(int id, TutorReportModel updatedModel)
        {
            var status = new StatusModel(false, String.Empty);

            try
            {
                using (var unitOfWork = new UnitOfWork <BelibaHomaDBEntities>())
                {
                    var TutorReportRepository = unitOfWork.GetRepository <ITutorReportRepository>();

                    var TutorReport = TutorReportRepository.GetByKey(id);
                    if (TutorReport != null)
                    {
                        TutorReport.MeetingsDescription = updatedModel.MeetingsDescription;
                        TutorReport.IsProblem           = updatedModel.IsProblem;

                        unitOfWork.SaveChanges();

                        status.Success = true;
                        status.Message = String.Format("הדיווח בתאריך {0} עודכנה בהצלחה", TutorReport.CreationTime);
                    }
                }
            }
            catch (Exception ex)
            {
                status.Message = String.Format("שגיאה במהלך עדכון הדיווח");
                LogService.Logger.Error(status.Message, ex);
            }

            return(status);
        }
Example #2
0
        public ActionResult Create(int tutorTraineeId)
        {
            var model = new TutorReportModel {
                TutorTraineeId = tutorTraineeId
            };

            return(View(model));
        }
Example #3
0
        public StatusModel <int> Add(TutorReportModel model, UserRole userRole)
        {
            var status = new StatusModel <int>(false, String.Empty, 0);

            try
            {
                using (var unitOfWork = new UnitOfWork <BelibaHomaDBEntities>())
                {
                    model.CreationTime = DateTime.Now;
                    var tutorReportRepository = unitOfWork.GetRepository <ITutorReportRepository>();
                    var entity = model.MapTo <TutorReport>();

                    //Retrieving Related Entities by using the repositories and GetById function (all but User which was not yet created)
                    var tutorTraineeRepository = unitOfWork.GetRepository <ITutorTraineeRepository>();
                    var tutorTrainee           = tutorTraineeRepository.GetByKey(model.TutorTraineeId);

                    //Server Side Validations
                    bool isNotLate =
                        tutorReportRepository.GetAll()
                        .ToList()
                        .Any(tr => tr.TutorTrainee.Status == (int)TTStatus.Active && tr.TutorTrainee.TutorId == tutorTrainee.Tutor.UserId && tr.CreationTime > DateTime.Now.AddDays(-21));
                    bool isReport = tutorReportRepository.GetAll()
                                    .ToList()
                                    .Any(tr => tr.TutorTrainee.Status == (int)TTStatus.Active && tr.TutorTrainee.TutorId == tutorTrainee.Tutor.UserId);

                    if (userRole == UserRole.Trainee && isNotLate == false && isReport)
                    {
                        status.Message = "לא הוזן דיווח כבר למעלה מ-3 שבועות.\nאנא פנה אל הרכז האזורי לעזרה.";
                        throw new System.ArgumentException(status.Message, "model");
                    }

                    //Linking the Complexed entities to the retrieved ones
                    entity.TutorTrainee = tutorTrainee;

                    //entity.relevantmajor= מה ששמרתי מהרפוסיטורים
                    tutorReportRepository.Add(entity);

                    unitOfWork.SaveChanges();

                    status.Data = entity.Id;

                    status.Success = true;
                    status.Message = String.Format("הדיווח בתאריך {0} הוזן בהצלחה", model.CreationTime);
                }
            }
            catch (Exception ex)
            {
                if (status.Message == String.Empty)
                {
                    status.Message = String.Format("שגיאה במהלך הזנת הדיווח");
                }
                LogService.Logger.Error(status.Message, ex);
            }

            return(status);
        }
Example #4
0
        public ActionResult Create(TutorReportModel model)
        {
            var result = _tutorReportService.Add(model, CurrentUser.UserRole);
            var id     = model.TutorTraineeId;

            if (result.Success)
            {
                if (model.IsProblem)
                {
                    var status = _alertService.AddInervention(result.Data);
                    if (!status.Success)
                    {
                        return(Error(status));
                    }
                }
                return(RedirectToAction("TutorTraineeReports", new { id = id }));
            }
            return(Error(result));
        }
Example #5
0
        public ActionResult Edit(int id, TutorReportModel model)
        {
            var result         = _tutorReportService.Update(id, model);
            var tutorTraineeId = model.TutorTraineeId;

            if (result.Success)
            {
                if (model.IsProblem)
                {
                    result = _alertService.AddInervention(model.Id);
                    if (!result.Success)
                    {
                        return(Error(result));
                    }
                }
                //return RedirectToAction("Index");
                return(RedirectToAction("TutorTraineeReports", new { id = tutorTraineeId }));
            }
            return(Error(result));
        }