/// <summary> /// The Creates entity for StoreViewModel. /// </summary> /// <param name="viewModel">The viewModel <see cref="StoreViewModel"/>.</param> /// <returns>The <see cref="SimpleResponse{StoreViewModel}"/>.</returns> public SimpleResponse <StoreViewModel> Create(StoreViewModel model) { var response = new SimpleResponse <StoreViewModel>(); try { var validation = model.Validate(); if (validation.HasError) { return(new SimpleResponse <StoreViewModel> { Data = model, ResponseCode = BusinessResponseValues.ValidationErrorResult, ResponseMessage = validation.AllValidationMessages }); } using (var context = new PublicDbContext()) { var entity = Map <StoreViewModel, Store>(model); context.Store.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 StoreViewModel. /// </summary> /// <param name="viewModel">The viewModel <see cref="StoreViewModel"/>.</param> /// <returns>The <see cref="SimpleResponse"/>.</returns> public SimpleResponse Update(StoreViewModel 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 PublicDbContext()) { var entity = context.Store.SingleOrDefault(q => q.StoreId == model.StoreId); if (entity == null || entity == default(Store)) { response.ResponseCode = BusinessResponseValues.NullEntityValue; response.ResponseMessage = "Kayýt bulunamadý."; return(response); } MapTo(model, entity); // context.Store.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); }