コード例 #1
0
        public async Task <ToRespond> UpdateLogBook(int logBookId, LogBookRequest logBookRequest)
        {
            var logBook = await _dataContext.LogBooks.Where(x => x.LogBookId == logBookId)
                          .Include(x => x.Comment)
                          .Include(x => x.Grade)
                          .FirstOrDefaultAsync();

            if (logBook == null)
            {
                return(new ToRespond
                {
                    StatusCode = Helpers.NotFound,
                    StatusMessage = Helpers.StatusMessageNotFound
                });
            }
            if (logBookRequest == null)
            {
                return(new ToRespond
                {
                    StatusCode = Helpers.ObjectNull,
                    StatusMessage = Helpers.StatusMessageObjectNull
                });
            }

            if (!logBook.Comment.Any() || !logBook.Grade.Any())
            {
                var logbook = _mapper.Map <LogBook>(logBookRequest);

                _globalRepository.Update(logbook);
                var result = await _globalRepository.SaveAll();

                if (result != null)
                {
                    if (!result.Value)
                    {
                        return(new ToRespond()
                        {
                            StatusCode = Helpers.SaveError,
                            StatusMessage = Helpers.StatusMessageSaveError
                        });
                    }
                    return(new ToRespond()
                    {
                        StatusCode = Helpers.Success,
                        ObjectValue = _mapper.Map <LogBookResponse>(logbook),
                        StatusMessage = "Student LogBook Updated Successfully!!!"
                    });
                }
            }

            return(new ToRespond()
            {
                StatusCode = Helpers.SaveError,
                StatusMessage = "Can not update Student LogBook"
            });
        }
コード例 #2
0
        public async Task <ActionResult> FillLogBook([FromBody] LogBookRequest logBookRequest)
        {
            var result = await _logBookRepository.FillLogBook(logBookRequest);

            if (result.StatusCode == Helpers.Success)
            {
                return(StatusCode(StatusCodes.Status200OK, result));
            }
            else
            {
                return(StatusCode(StatusCodes.Status400BadRequest, result));
            }
        }
コード例 #3
0
        public async Task <ActionResult> UpdateLogBook(int logBookId, LogBookRequest logBookRequest)
        {
            var result = await _logBookRepository.UpdateLogBook(logBookId, logBookRequest);

            if (result.StatusCode == Helpers.Success)
            {
                return(StatusCode(StatusCodes.Status200OK, result));
            }
            else
            {
                return(StatusCode(StatusCodes.Status400BadRequest, result));
            }
        }
コード例 #4
0
        public async Task <ToRespond> FillLogBook(LogBookRequest logBookRequest)
        {
            if (logBookRequest == null)
            {
                return(new ToRespond()
                {
                    StatusCode = Helpers.NotFound,
                    StatusMessage = Helpers.StatusMessageNotFound
                });
            }

            var userId = Int32.Parse(_httpContextAccessor.HttpContext.User.Identity.Name);

            var student = await _dataContext.Students.Where(a => a.UserId == userId).SingleOrDefaultAsync();

            if (student == null)
            {
                return(new ToRespond()
                {
                    StatusCode = Helpers.NotFound,
                    StatusMessage = Helpers.StatusMessageNotFound
                });
            }

            if (student.EligiblityStatus == Helpers.Eligible)
            {
                var logbook = _mapper.Map <LogBook>(logBookRequest);
                logbook.StudentId = student.StudentId;
                logbook.Student   = student;
                //student.LogBook.Add(logbook);

                _globalRepository.Add(logbook);
                var result = await _globalRepository.SaveAll();


                foreach (var stuLogBook in student.LogBook)
                {
                    stuLogBook.LogBookId   = logbook.LogBookId;
                    stuLogBook.Student     = student;
                    stuLogBook.StudentId   = student.StudentId;
                    stuLogBook.Time        = logbook.Time;
                    stuLogBook.Description = logbook.Description;
                }

                _dataContext.Entry(student).State = EntityState.Modified;

                if (result != null)
                {
                    if (!result.Value)
                    {
                        return(new ToRespond()
                        {
                            StatusCode = Helpers.SaveError,
                            StatusMessage = Helpers.StatusMessageSaveError
                        });
                    }
                    return(new ToRespond()
                    {
                        StatusCode = Helpers.Success,
                        ObjectValue = _mapper.Map <LogBookResponse>(logbook),
                        StatusMessage = "Student LogBook created Successfully!!!"
                    });
                }
            }
            else
            {
                return(new ToRespond()
                {
                    StatusCode = Helpers.SaveError,
                    StatusMessage = "Non Eligible Student Cannot fill the form"
                });
            }

            return(new ToRespond()
            {
                StatusCode = Helpers.SaveError,
                StatusMessage = Helpers.StatusMessageSaveError
            });
        }