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