public IHttpActionResult CreateNewVolunteer(CreateNewVolunteerDTO model) { if (!Request.Headers.Contains("apiKey")) { return(Unauthorized()); } string apiKey = Request.Headers.GetValues("apiKey").First(); if (!ApiHelper.CheckKey(apiKey)) { return(Unauthorized()); } try { var serviceResult = _accountService.CreateNewVolunteer(model); return(Ok(serviceResult)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
protected void buttonCreateNewVolunteer_Click(object sender, EventArgs e) { try { var newVolunteer = new CreateNewVolunteerDTO(); if (!string.IsNullOrWhiteSpace(Volunteer_Password.Text) && !string.IsNullOrWhiteSpace(Volunteer_PasswordAgain.Text)) { if (Volunteer_Password.Text != Volunteer_PasswordAgain.Text) { throw new Exception("Şifre bilgisi uyuşmuyor!"); } } newVolunteer.UserTypeId = (int)EnumUserType.Volunteer; newVolunteer.FirstName = Volunteer_FirstName.Text; newVolunteer.LastName = Volunteer_LastName.Text; newVolunteer.BirthDate = Volunteer_BirthDate.SelectedDate.Value; newVolunteer.PhoneNum = Volunteer_Phone.Text; newVolunteer.Username = Volunteer_TCKN.Text; newVolunteer.Email = Volunteer_Email.Text; newVolunteer.Password = Volunteer_Password.Text; var collection = RadComboBoxInterest.CheckedItems; if (collection.Count != 3) { throw new Exception("Lütfen üç ilgi alanı seçiniz!"); } var temp = collection.Count; if (collection.Count != 0) { foreach (var item in collection) { if (temp == 3) { newVolunteer.Interest3Id = Convert.ToInt32(item.Value); temp--; } else if (temp == 2) { newVolunteer.Interest2Id = Convert.ToInt32(item.Value); temp--; } else { newVolunteer.Interest1Id = Convert.ToInt32(item.Value); } } } if (checkIsStudent.SelectedValue == "1") //Student { newVolunteer.IsStudent = true; newVolunteer.UniversityId = Convert.ToInt32(universityDropDownListV.SelectedValue); newVolunteer.DepartmentId = Convert.ToInt32(departmentDropDownListV.SelectedValue); newVolunteer.Class = Volunteer_Class.Text; } else if (checkIsStudent.SelectedValue == "2") //Not student { newVolunteer.OccupationId = Convert.ToInt32(Volunteer_Occupation.SelectedValue); } ServiceResult <long> serviceResult = new ServiceResult <long>(); var queryString = new Dictionary <string, string>(); var response = ApiHelper.CallSendApiMethod(ApiKeys.AccountApiUrl, "CreateNewVolunteer", queryString, newVolunteer); if (!response.IsSuccessStatusCode) { throw new Exception("Hata oluştu!"); } var data = response.Content.ReadAsStringAsync().Result; serviceResult = JsonConvert.DeserializeObject <ServiceResult <long> >(data); if (serviceResult.ServiceResultType != EnumServiceResultType.Success) { throw new Exception(serviceResult.ErrorMessage); } labelErrorMessage.Text = "Gönüllü üyeliği oluşturuldu."; labelErrorMessage.Visible = true; } catch (Exception ex) { labelErrorMessage.Text = ex.Message; labelErrorMessage.Visible = true; } }
public ServiceResult <long> CreateNewVolunteer(CreateNewVolunteerDTO model) { string errorMessage = string.Empty; EnumServiceResultType serviceResultType = EnumServiceResultType.Unspecified; long result = -1; try { var anyExistingUser = _userRepository.Entities.Any(p => p.Username == model.Username && p.Email == model.Email && p.IsActive); if (anyExistingUser) { throw new Exception("Kullanıcı bilgisi mevcut."); } var newUser = new Contracts.Entities.EF.User { IsActive = true, Password = model.Password, Username = model.Username, UserTypeId = model.UserTypeId, Email = model.Email }; var newVolunteer = new Volunteer { BirthDate = model.BirthDate, Class = model.Class, DepartmentId = model.DepartmentId, FirstName = model.FirstName, IsStudent = model.IsStudent, LastName = model.LastName, OccupationId = model.OccupationId, PhoneNumber = model.PhoneNum, UniversityId = model.UniversityId }; var newInterest1 = new InterestVolunteer { ActivityId = model.Interest1Id }; var newInterest2 = new InterestVolunteer { ActivityId = model.Interest2Id }; var newInterest3 = new InterestVolunteer { ActivityId = model.Interest3Id }; newUser.Volunteer.Add(newVolunteer); newVolunteer.InterestVolunteer.Add(newInterest1); newVolunteer.InterestVolunteer.Add(newInterest2); newVolunteer.InterestVolunteer.Add(newInterest3); var userResult = _userRepository.Add(newUser); _unitOfWork.SaveChanges(); result = userResult.Id; serviceResultType = EnumServiceResultType.Success; } catch (Exception ex) { errorMessage = ex.Message; serviceResultType = EnumServiceResultType.Error; } return(new ServiceResult <long> { ErrorMessage = errorMessage, Result = result, ServiceResultType = serviceResultType }); }