示例#1
0
        /// <summary>
        /// Get Volunteer by id
        /// </summary>
        /// <param name="id">Volunteer id</param>
        /// <returns>Volunteer json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_volunteerService.GetVolunteer - volunteerId: " + id + " ");

                var volunteer = new VolunteerViewModel(_volunteerService.GetVolunteer(id));

                log.Debug("_volunteerService.GetVolunteer - " + VolunteerViewModel.FormatVolunteerViewModel(volunteer));

                log.Debug("result: 'success'");

                //return Json(volunteer, JsonRequestBehavior.AllowGet);
                //return Content(JsonConvert.SerializeObject(volunteer), "application/json");
                //return volunteer;
                //return JsonConvert.SerializeObject(volunteer);
                return(Ok(volunteer));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
示例#2
0
        public IActionResult GetVolunteer(int Id)
        {
            var volunteer = _volunteerService.GetVolunteer(Id);

            if (volunteer != null)
            {
                return(Ok(volunteer));
            }

            return(NotFound($"Volunteer with ID: {Id} is not found."));
        }
示例#3
0
        public async Task <ActionResult> Details(Guid id)
        {
            VolunteerViewModel userModel = await _volunteerService.GetVolunteer(id);

            if (userModel == null)
            {
                AddMessageToTempData(CommonResources.NoDataFound, BusinessSolutions.MVCCommon.MessageType.Error);
                return(RedirectToAction("Index"));
            }
            return(View(userModel));
        }
示例#4
0
        public IActionResult Detail(int id)
        {
            VolunteerDetailViewModel model;

            /*model = new VolunteerDetailViewModel()
             * {
             *  Username = "******",
             *  FirstName = "Veselin",
             *  LastName = "Penev",
             *  Age = 25,
             *  Contact = "*****@*****.**"
             * };*/

            try
            {
                model = service.GetVolunteer(id);
            }
            catch (IndexOutOfRangeException)
            {
                return(this.View("InvalidAction", new InvalidActionViewModel()
                {
                    ErrorMessage = "Failed to execute last command:\nIndex was out of range"
                }));
            }
            catch (ArgumentException e)
            {
                return(this.View("InvalidAction", new InvalidActionViewModel()
                {
                    ErrorMessage = e.Message
                }));
            }

            return(View(model));
        }
示例#5
0
        public async Task UpdateVolunteer_WithValidData_UpdateVolunteer()
        {
            var volunteer = new Application.Models.VolunteerViewModel
            {
                Address    = "Address",
                CityId     = _commonSettingDataContext.Cities.First().Id,
                Email      = "*****@*****.**",
                Gender     = Application.Models.Genders.Male,
                Name       = "Name",
                Notes      = "Notes",
                Phone      = "Phone",
                DistrictId = _commonSettingDataContext.Districts.First().Id,
            };
            var result = await _volunteerService.AddVolunteer(volunteer);

            Assert.IsTrue(result.Succeeded);

            volunteer.Address = "UpdatedAddress";
            volunteer.Name    = "UpdateName";

            result = await _volunteerService.UpdateVolunteer(volunteer);

            Assert.IsTrue(result.Succeeded);

            var updatedVolunteer = await _volunteerService.GetVolunteer(volunteer.Id);

            Assert.AreEqual(updatedVolunteer.Address, volunteer.Address);
            Assert.AreEqual(updatedVolunteer.Name, volunteer.Name);
        }
示例#6
0
        /// <summary>
        /// Get Volunteer by id
        /// </summary>
        /// <param name="id">Volunteer id</param>
        /// <returns>Volunteer</returns>
        public VolunteerDataContract Get(int id)
        {
            try
            {
                // get
                log.Debug("_volunteerService.GetVolunteer - volunteerId: " + id + " ");

                var volunteer = new VolunteerDataContract(_volunteerService.GetVolunteer(id));

                log.Debug("_volunteerService.GetVolunteer - " + VolunteerDataContract.FormatVolunteerDataContract(volunteer));

                log.Debug("result: 'success'");

                return(volunteer);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }