public HttpResponseMessage SaveIndividual(IndividualViewModel viewModel) { Individual individual; if (viewModel.Id == -1) { individual = new Individual { Id = -1, TreeId = viewModel.TreeId, FirstName = viewModel.FirstName, LastName = viewModel.LastName }; switch (viewModel.Sex) { case "Male": individual.Sex = Sex.Male; break; case "Female": individual.Sex = Sex.Female; break; default: individual.Sex = Sex.Unknown; break; } _individualService.Add(individual); } else { individual = _individualService.Get(viewModel.Id, viewModel.TreeId); individual.FirstName = viewModel.FirstName; individual.LastName = viewModel.LastName; if (viewModel.ImageId > 0) { individual.ImageId = viewModel.ImageId; } _individualService.Update(individual); } var response = new { id = individual.Id }; return(Request.CreateResponse(HttpStatusCode.OK, response)); }
/// <summary> /// Create or update Individual /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, RoutedEventArgs e) { CustomPrincipal customPrincipal = Thread.CurrentPrincipal as CustomPrincipal; CurrentIndividual.CreatedBy = new UserViewModel() { Id = customPrincipal.Identity.Id }; //if (String.IsNullOrEmpty(CurrentIndividual.Mobile)) //{ // MainWindow.WarningMessage = "Morate uneti mobilni!"; // return; //} //int PIB = 0; //Int32.TryParse(CurrentIndividual.PIB, out PIB); IndividualResponse response; //// If by any chance PIB exists in the database //if (response.Success == false) //{ // if (CurrentIndividual.Id != response.Individual.Id) // { // notifier.ShowError("PIB mora biti jedinstven!"); // return; // } //} if (CurrentIndividual.Id > 0) { response = individualService.Update(CurrentIndividual); } else { response = individualService.Create(CurrentIndividual); } if (response.Success) { IndividualCreatedUpdated(response.Individual); FlyoutHelper.CloseFlyout(this); } else { notifier.ShowError(response.Message); } }