Пример #1
0
        public async Task <ActionResult> StudentPlacement([FromForm] PlacementRequestDto placementRequest)
        {
            var result = await _studentRepository.StudentPlacement(placementRequest);

            if (result.StatusCode == Helpers.Success)
            {
                return(StatusCode(StatusCodes.Status200OK, result));
            }
            else
            {
                return(StatusCode(StatusCodes.Status400BadRequest, result));
            }
        }
Пример #2
0
        public async Task <ToRespond> UpdateStudentPlacement(int placementId, PlacementRequestDto placementRequest)
        {
            var placement = await _dataContext.Placements.FindAsync(placementId);

            var student = await _dataContext.Students.Where(x => x.PlacementId == placementId)
                          .FirstOrDefaultAsync();

            if (placement == null || student == null)
            {
                return(new ToRespond
                {
                    StatusCode = Helpers.NotFound,
                    StatusMessage = Helpers.StatusMessageNotFound
                });
            }
            if (placementRequest == null)
            {
                return(new ToRespond
                {
                    StatusCode = Helpers.ObjectNull,
                    StatusMessage = Helpers.StatusMessageObjectNull
                });
            }

            if (student.EligiblityStatus != Helpers.Eligible)
            {
                placement.MatricNumber       = placementRequest.MatricNumber;
                placement.FullName           = placementRequest.FirstName + placementRequest.LastName;
                placement.RegistrationNumber = placementRequest.RegistrationNumber;
                placement.Department         = placementRequest.Department;
                placement.Programm           = placementRequest.Programm;
                placement.Level                 = placementRequest.Level;
                placement.CompanyName           = placementRequest.CompanyName;
                placement.CompanyAddress        = placementRequest.CompanyAddress;
                placement.SectionOfWork         = placementRequest.SectionOfWork;
                placement.EmailAddressOfCompany = placementRequest.EmailAddressOfCompany;

                if (placementRequest.OfferLetter != null || student.PictureUrl != null)
                {
                    var resultImage = _cloudinaryRepository.UploadFileToCloudinary(placementRequest.OfferLetter);
                    var image       = (RawUploadResult)resultImage.ObjectValue;
                    placement.OfferLetter    = image.Uri.ToString();
                    placement.StudentPicture = student.PictureUrl;
                }

                //var dbTransaction = await _dataContext.Database.BeginTransactionAsync();

                _globalRepository.Update(placement);
                //student.Placement = placement;
                var result = await _globalRepository.SaveAll();

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

                if (result != null)
                {
                    if (!result.Value)
                    {
                        return(new ToRespond()
                        {
                            StatusCode = Helpers.SaveError,
                            StatusMessage = Helpers.StatusMessageSaveError
                        });
                    }
                    //await dbTransaction.CommitAsync();
                    return(new ToRespond()
                    {
                        StatusCode = Helpers.Success,
                        ObjectValue = _mapper.Map <PlacementResponse>(placement),
                        StatusMessage = "Placement Updated Successfully!!!"
                    });
                }
            }

            return(new ToRespond()
            {
                StatusCode = Helpers.SaveError,
                StatusMessage = "Your Placement Have been accepted already, so you can't edit again"
            });
        }
Пример #3
0
        public async Task <ToRespond> StudentPlacement(PlacementRequestDto placementRequest)
        {
            if (placementRequest == null)
            {
                return(new ToRespond()
                {
                    StatusCode = Helpers.ObjectNull,
                    StatusMessage = Helpers.StatusMessageObjectNull
                });
            }

            //var studentId = Int32.Parse(_httpContextAccessor.HttpContext.User.Claims
            //                                .FirstOrDefault(x => x.Type == Helpers.ClaimType_StudentId)
            //                                .Value);

            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
                });
            }
            //var student = await _dataContext.Students.FindAsync(studentId);

            var placement = new Placement
            {
                MatricNumber       = placementRequest.MatricNumber,
                FullName           = placementRequest.FirstName + placementRequest.LastName,
                RegistrationNumber = placementRequest.RegistrationNumber,
                Department         = placementRequest.Department,
                Programm           = placementRequest.Programm,
                Level                 = placementRequest.Level,
                CompanyName           = placementRequest.CompanyName,
                CompanyAddress        = placementRequest.CompanyAddress,
                SectionOfWork         = placementRequest.SectionOfWork,
                EmailAddressOfCompany = placementRequest.EmailAddressOfCompany,
            };

            if (placementRequest.OfferLetter != null || student.PictureUrl != null)
            {
                var resultImage = _cloudinaryRepository.UploadFileToCloudinary(placementRequest.OfferLetter);
                var image       = (RawUploadResult)resultImage.ObjectValue;
                placement.OfferLetter    = image.Uri.ToString();
                placement.StudentPicture = student.PictureUrl;
            }

            var dbTransaction = await _dataContext.Database.BeginTransactionAsync();

            _globalRepository.Add(placement);
            student.EligiblityStatus = Helpers.Pending;
            student.Placement        = placement;
            var result = await _globalRepository.SaveAll();

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

            if (result != null)
            {
                if (!result.Value)
                {
                    return(new ToRespond()
                    {
                        StatusCode = Helpers.SaveError,
                        StatusMessage = Helpers.StatusMessageSaveError
                    });
                }
                await dbTransaction.CommitAsync();

                return(new ToRespond()
                {
                    StatusCode = Helpers.Success,
                    ObjectValue = _mapper.Map <PlacementResponse>(placement),
                    StatusMessage = "Placement Registered Successfully!!!"
                });
            }

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