/// <summary> /// The Creates entity for LanguageViewModel. /// </summary> /// <param name="viewModel">The viewModel <see cref="LanguageViewModel"/>.</param> /// <returns>The <see cref="SimpleResponse{LanguageViewModel}"/>.</returns> public SimpleResponse <LanguageViewModel> Create(LanguageViewModel model) { var response = new SimpleResponse <LanguageViewModel>(); try { var validation = model.Validate(); if (validation.HasError) { return(new SimpleResponse <LanguageViewModel> { Data = model, ResponseCode = BusinessResponseValues.ValidationErrorResult, ResponseMessage = validation.AllValidationMessages }); } using (var context = new PublicCoreDbContext()) { var entity = Map <LanguageViewModel, Language>(model); context.Language.Add(entity); response.ResponseCode = context.SaveChanges(); } } catch (Exception ex) { response.ResponseCode = BusinessResponseValues.InternalError; response.ResponseMessage = "Ekleme iþleminde hata oluþtu."; DayLogger.Error(ex); } return(response); }
/// <summary> /// Updates entity for LanguageViewModel. /// </summary> /// <param name="viewModel">The viewModel <see cref="LanguageViewModel"/>.</param> /// <returns>The <see cref="SimpleResponse"/>.</returns> public SimpleResponse Update(LanguageViewModel model) { var response = new SimpleResponse(); try { var validation = model.Validate(); if (validation.HasError) { return(new SimpleResponse { ResponseCode = BusinessResponseValues.ValidationErrorResult, ResponseMessage = validation.AllValidationMessages }); } using (var context = new PublicCoreDbContext()) { var entity = context.Language.SingleOrDefault(q => q.LanguageId == model.LanguageId); if (entity == null || entity == default(Language)) { response.ResponseCode = BusinessResponseValues.NullEntityValue; response.ResponseMessage = "Kayýt bulunamadý."; return(response); } MapTo(model, entity); context.Language.Attach(entity); // context.Entry(entity).State = EntityState.Modified; response.ResponseCode = context.SaveChanges(); } } catch (Exception ex) { response.ResponseCode = BusinessResponseValues.InternalError; response.ResponseMessage = "Güncelleme iþleminde hata oluþtu."; DayLogger.Error(ex); } return(response); }