protected void buttonCreateNGOHead_Click(object sender, EventArgs e) { try { //ValidatorNGOHead_TCKN.Enabled = true; //ValidatorNGOHead_FirstName.Enabled = true; //ValidatorNGOHead_LastName.Enabled = true; //ValidatorNGOHead_BirthDate.Enabled = true; //ValidatorNGOHead_DutyStartDate.Enabled = true; //ValidatorNGOHead_Email.Enabled = true; //ValidatorNGOHead_Phone.Enabled = true; //ValidatorNGOHead_Password.Enabled = true; //ValidatorNGOHead_Password2.Enabled = true; var newNGOHead = new CreateNewNGOHeadDTO(); if (!string.IsNullOrWhiteSpace(NGOHead_Password.Text) && !string.IsNullOrWhiteSpace(NGOHead_Password2.Text)) { if (NGOHead_Password.Text != NGOHead_Password2.Text) { throw new Exception("Şifre bilgisi uyuşmuyor!"); } } newNGOHead.UserTypeId = (int)EnumUserType.NGOHead; newNGOHead.FirstName = NGOHead_FirstName.Text; newNGOHead.LastName = NGOHead_LastName.Text; newNGOHead.BirthDate = NGOHead_BirthDate.SelectedDate.Value; newNGOHead.PhoneNum = NGOHead_Phone.Text; newNGOHead.Username = NGOHead_TCKN.Text; newNGOHead.Email = NGOHead_Email.Text; newNGOHead.Password = NGOHead_Password.Text; newNGOHead.Password = NGOHead_Password.Text; newNGOHead.DutyStartDate = NGOHead_DutyStartDate.SelectedDate.Value; ServiceResult <long> serviceResult = new ServiceResult <long>(); var queryString = new Dictionary <string, string>(); var response = ApiHelper.CallSendApiMethod(ApiKeys.AccountApiUrl, "CreateNewNGOHead", queryString, newNGOHead); 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 = "Organizasyon Başkanı üyeliği oluşturuldu."; labelErrorMessage.Visible = true; } catch (Exception ex) { labelErrorMessage.Text = ex.Message; labelErrorMessage.Visible = true; } }
public ServiceResult <long> CreateNewNGOHead(CreateNewNGOHeadDTO 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 newNGOHead = new NgoHead { FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNum }; newUser.NgoHead.Add(newNGOHead); 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 }); }
public IHttpActionResult CreateNewNGOHead(CreateNewNGOHeadDTO 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.CreateNewNGOHead(model); return(Ok(serviceResult)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }