Example #1
0
        private VolunteerDTO Create(VolunteerViewModel viewModel)
        {
            try
            {
                log.Debug(VolunteerViewModel.FormatVolunteerViewModel(viewModel));

                VolunteerDTO volunteer = new VolunteerDTO();

                // copy values
                viewModel.UpdateDTO(volunteer, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                volunteer.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                volunteer.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_volunteerService.AddVolunteer - " + VolunteerDTO.FormatVolunteerDTO(volunteer));

                int id = _volunteerService.AddVolunteer(volunteer);

                volunteer.VolunteerId = id;

                log.Debug("result: 'success', id: " + id);

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

                throw;
            }
        }
Example #2
0
        public async Task CreateVolunteer_WithValidData_CreateVolunteer()
        {
            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);
        }
Example #3
0
        public bool Post([FromBody] VolunteerDto volunteermodel)
        {
            var volunteer = _mapper.Map <Volunteer>(volunteermodel);
            var register  = _volunteerservice.AddVolunteer(volunteer);

            return(register);
        }
Example #4
0
        public async Task <ActionResult> Create(VolunteerViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var entityResult = await _volunteerService.AddVolunteer(model);

                    if (entityResult.Succeeded)
                    {
                        AddMessageToTempData(CommonResources.SavedSuccessfullyMessage
                                             , BusinessSolutions.MVCCommon.MessageType.Success);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        foreach (var error in entityResult.ValidationErrors)
                        {
                            ModelState.AddModelError("", error.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.Logger.Error(ex);
                AddMessageToView(CommonResources.UnExpectedError
                                 , BusinessSolutions.MVCCommon.MessageType.Error);
            }

            GetRoles();
            return(View(model));
        }
Example #5
0
        public IActionResult AddVolunteer(Volunteer volunteer)
        {
            _volunteerService.AddVolunteer(volunteer);

            return(Created(HttpContext.Request.Scheme + "://" + HttpContext.Request.Host + HttpContext.Request.Path + "/" + volunteer.Id, volunteer));
        }