Exemple #1
0
        public async Task <IActionResult> Update([FromBody] StudentUpdateRequest request)
        {
            var contract = mapper.Map <StudentContract>(request);
            await studentService.Update(contract);

            return(Ok());
        }
Exemple #2
0
        public async Task <int> Update(StudentUpdateRequest request)
        {
            var province = _context.Provinces.First(x => x.ProvinceName == request.ProvinceName);
            var district = _context.Districts.First(x => x.DistrictName == request.DistrictName);
            var commune  = _context.Communes.First(x => x.CommuneName == request.CommuneName);
            var student  = await _context.Students.FindAsync(request.Id);

            if (student == null)
            {
                throw new StudentException("Can not find the student");
            }
            student.Name  = request.Name;
            student.Phone = request.Phone;
            student.Yob   = request.Yob;
            //string[] arr = request.Address.Split(',');
            //string address = null;
            //for (int i = 0; i < arr.Length-3; i++)
            //{
            //    address += arr[i] + ",";
            //}
            student.Address    = request.Address + ", " + province.ProvinceName + ", " + district.DistrictName + ", " + commune.CommuneName;
            student.CommuneId  = commune.CommuneId;
            student.DistrictId = district.DistrictId;
            student.ProvinceId = province.ProvinceId;
            return(await _context.SaveChangesAsync());
        }
        //Id=UserId
        public StudentResponse Update(Guid Id, StudentUpdateRequest request)
        {
            Guid ID = _studentDao.UpdateStudent(Id, request);

            var response = new StudentResponse(_userService.UpdateUser(Id, request), request.Index, ID);

            return(response);
        }
Exemple #4
0
        public IActionResult UpdateStudent(StudentUpdateRequest request)
        {
            var studentUpdateCommand = new StudentUpdateCommand(request);

            _commandProccessor.Execute(studentUpdateCommand);

            return(_commandProccessor.Result.Status != CommandResultStatus.Success ?
                   BadRequest(_commandProccessor.Result.Message) : Ok(_commandProccessor.Result.Message));
        }
        public async Task <IActionResult> Update(StudentUpdateRequest request)
        {
            var student = await _studentService.Update(request);

            if (student == 0)
            {
                return(BadRequest());
            }
            return(RedirectToAction("Index"));
        }
Exemple #6
0
        public async Task <IActionResult> Update([FromForm] StudentUpdateRequest request)
        {
            var affected = await _manageStudentService.Update(request);

            if (affected == 0)
            {
                return(BadRequest());
            }
            return(Ok());
        }
Exemple #7
0
        public IActionResult EditStudent(StudentUpdateRequest request)
        {
            var st    = _context.Student.Find(request.IndexNumber);
            var value = request.LastName;

            if (st != null)
            {
                st.FirstName = request.FirstName;
                st.LastName  = request.LastName;

                _context.Student.Update(st);
                _context.SaveChanges();
            }


            return(Ok(st));
        }
Exemple #8
0
        public IActionResult DeleteStudent(StudentUpdateRequest request)
        {
            var st = _context.Student.Find(request.IndexNumber);

            if (st != null)
            {
                try
                {
                    _context.Student.Remove(st);
                    _context.SaveChanges();
                }catch (Exception ex)
                {
                    return(BadRequest("Podany student nie widnieje w bazie!"));
                }
            }

            return(Ok(200));
        }
Exemple #9
0
        public async Task <ApiSuccessResponse> UpdateAsync(long id, StudentUpdateRequest request)
        {
            var student = await _unitOfWork.StudentRepository.FindSingleAsync(x => x.StudentId == id);

            if (student == null)
            {
                throw new MyAppException("The student with a given id is not found!");
            }

            var studentEmailAlreadyExists =
                await _unitOfWork.StudentRepository.FindSingleAsync(x => x.Email == request.Email && x.Email != student.Email);

            if (studentEmailAlreadyExists != null)
            {
                throw new MyAppException("The student with a given email already exists in our system!");
            }

            var studentRollNoAlreadyExists =
                await _unitOfWork.StudentRepository.FindSingleAsync(x => x.RollNo == request.RollNo && x.RollNo != student.RollNo);

            if (studentRollNoAlreadyExists != null)
            {
                throw new MyAppException("The student with a given roll no. already exists in our system!");
            }

            student.Name         = request.Name;
            student.Email        = request.Email;
            student.RollNo       = request.RollNo;
            student.DepartmentId = request.DepartmentId;

            _unitOfWork.StudentRepository.Update(student);
            if (await _unitOfWork.AppSaveChangesAsync())
            {
                return new ApiSuccessResponse()
                       {
                           StatusCode = 200,
                           Message    = "The student has been successfully updated."
                       }
            }
            ;

            throw new MyAppException("Something went wrong!");
        }
Exemple #10
0
        public async Task <Student> UpdateAsync(string roll, StudentUpdateRequest request)
        {
            var student = await _unitOfWork.StudentRepository.GetSingleAsync(x => x.RollNo == roll);

            if (student == null)
            {
                throw new ExceptionManagementHelper("No found Data");
            }

            student.Name   = request.Name;
            student.RollNo = request.RollNo;
            student.Email  = request.Email;
            _unitOfWork.StudentRepository.Update(student);


            if (await _unitOfWork.DbSaveChangeAsync())
            {
                return(student);
            }
            throw new ExceptionManagementHelper("Student Data Not save");
        }
        public async Task <Student> UpdateAsync(string roll, StudentUpdateRequest request)
        {
            var student = await _unitOfWork.StudentRepository.GetAAsynce(x => x.RollNo == roll);

            if (student == null)
            {
                throw new MyAppException("No found Data");
            }

            student.Name   = request.Name;
            student.RollNo = request.RollNo;
            student.Email  = request.Email;
            _unitOfWork.StudentRepository.UpdateAsyc(student);


            if (await _unitOfWork.ApplicationSaveChangesAsync())
            {
                return(student);
            }
            throw new MyAppException("Student Data Not save");
        }
        public Guid UpdateStudent(Guid Id, StudentUpdateRequest student)
        {
            Guid StudentId = Guid.NewGuid();

            Create();
            using (connection)
            {
                SqlCommand Usercommand = new SqlCommand("Select StudentId From [dbo].[User] WHERE ID = @Id ", connection);
                Usercommand.Parameters.Add("@Id", SqlDbType.UniqueIdentifier);
                Usercommand.Parameters["@Id"].Value = Id;
                using (var reader = Usercommand.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        StudentId = Guid.Parse(reader["StudentId"].ToString());
                    }
                }
                if (!string.IsNullOrWhiteSpace(student.Index))
                {
                    SqlCommand command = new SqlCommand("UPDATE dbo.Student SET Index =@Index,LastUpdatedAt=@LastUpdatedAt  WHERE ID = @Id ", connection);
                    command.Parameters.Add("@Id", SqlDbType.UniqueIdentifier);
                    command.Parameters["@Id"].Value = StudentId;

                    command.Parameters.Add("@Index", SqlDbType.VarChar);
                    command.Parameters["@Index"].Value = student.Index;

                    command.Parameters.Add("@LastUpdatedAt", SqlDbType.DateTime);
                    command.Parameters["@LastUpdatedAt"].Value = DateTime.Now;


                    command.ExecuteNonQuery();
                }
                connection.Close();
            }

            return(StudentId);
        }
Exemple #13
0
        public async Task <Student> UpdateStudentAsync(string rollNo, StudentUpdateRequest request)
        {
            var astudent = await _unitOfWork.StudentRepository.GetAAsync(x => x.RollNo == rollNo);

            if (astudent == null)
            {
                throw  new MyAppException("No data found");
            }
            Student student = new Student
            {
                Name         = request.Name,
                Email        = request.Email,
                RollNo       = request.RollNo,
                DepartmentId = request.DepartmentId
            };

            _unitOfWork.StudentRepository.UpdateAsync(student);
            if (!await _unitOfWork.ApplicationSaveChangesAsync())
            {
                throw  new MyAppException("Some thing is wrong");
            }

            return(student);
        }
Exemple #14
0
 public async Task <ActionResult> Update(string roll, [FromForm]  StudentUpdateRequest request)
 {
     return(Ok(await _studentService.UpdateAsync(roll, request)));
 }
Exemple #15
0
 public async Task <ActionResult> UpdateStudent(string rollNo, StudentUpdateRequest aStudent)
 {
     return(Ok(await _studentService.UpdateStudentAsync(rollNo, aStudent)));
 }
Exemple #16
0
 public StudentResponse Put(Guid id, [FromBody] StudentUpdateRequest request)
 {
     return(_studentService.Update(id, request));
 }
Exemple #17
0
 public void Update(StudentUpdateRequest studentUpdateRequest, Guid userId)
 {
     throw new NotImplementedException();
 }
Exemple #18
0
 public async Task <IActionResult> Update(long id, StudentUpdateRequest request)
 {
     return(Ok(await _studentService.UpdateAsync(id, request)));
 }
Exemple #19
0
 public StudentUpdateCommand(StudentUpdateRequest request)
 {
     _request = request;
 }