public ActionResult Edit(int id, ChequeViewModel model) { if (ModelState.IsValid) { var cheque = Mapper.Map <ChequeViewModel, Cheque>(model); _chequeApplicationService.Update(cheque); return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IActionResult> Delete(Guid id, ChequeViewModel cheque) { var commandResult = await _chequeApplicationService.Remove(cheque); if (commandResult.Success) { NotifyCommandResultSuccess(); return(RedirectToAction(nameof(Index))); } else { NotifyCommandResultErrors(commandResult.Errors); } return(View(cheque)); }
public static IList <ChequeViewModel> MapToViewModelsList(this IList <Cheque> cheques) { List <ChequeViewModel> viewModels = new List <ChequeViewModel>(); if (cheques != null && cheques.Count > 0) { foreach (Cheque c in cheques) { ChequeViewModel viewModel = c.MapToViewModel(); if (viewModel != null) { viewModels.Add(viewModel); } } } return(viewModels); }
public static ChequeViewModel MapToViewModel(this Cheque Cheque) { ChequeViewModel viewModel = null; if (Cheque != null) { viewModel = new ChequeViewModel { Amount = Cheque.Amount, ChequeId = Cheque.Id, Comments = Cheque.Comments, Description = Cheque.Description, MonthlyBudgetId = Cheque.MonthlyBudgetId, Payee = Cheque.Payee, PaymentDate = Cheque.PaymentDate, CreationDate = Cheque.CreationDate, LastModified = Cheque.LastModifited }; } return(viewModel); }
public static Cheque MapToModel(this ChequeViewModel viewModel) { Cheque cheque = null; if (viewModel != null) { cheque = new Cheque { Amount = viewModel.Amount, Comments = viewModel.Comments, Description = viewModel.Description, Id = viewModel.ChequeId, MonthlyBudgetId = viewModel.MonthlyBudgetId, Payee = viewModel.Payee, PaymentDate = viewModel.PaymentDate, CreationDate = viewModel.CreationDate, LastModifited = viewModel.LastModified }; } return(cheque); }
public async Task <IActionResult> Create(ChequeViewModel cheque) { if (!ModelState.IsValid) { NotifyModelStateErrors(); return(View(cheque)); } var commandResult = await _chequeApplicationService.Add(cheque); if (commandResult.Success) { NotifyCommandResultSuccess(); return(RedirectToAction(nameof(Index))); } else { NotifyCommandResultErrors(commandResult.Errors); } return(View(cheque)); }
public HttpResponseMessage GetChequeById(int id) { try { var result = new ChequeViewModel(); var model = _financeiroService.ObterChequePorId(id); if (model != null) { Mapper.CreateMap <Cheque, ChequeViewModel>(); result = Mapper.Map <Cheque, ChequeViewModel>(model); result.NomePessoa = model.Pessoa.Nome; } return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
private void InitializeViewModel() { _viewModel = new ChequeViewModel(); _viewModel.AddCommand = new Command(() => { var record = new RecordModel() { UserId = GlobalVariables.UserId, RecordType = _viewModel.Entities.Count > 0 ? _viewModel.Entities.Last().RecordType : RecordType.Expense }; record.PropertyChanged += (sender, e) => { if (e.PropertyName == nameof(RecordModel.Value) || e.PropertyName == nameof(RecordModel.RecordType)) { _viewModel.RefreshTotalAmount(); } }; _viewModel.Entities.Add(record); }); _viewModel.DuplicateCommand = new DataGridSelectedItemCommand <RecordModel>(GridRecords, (item) => { _viewModel.Entities.Add(new RecordModel() { Description = item.Description, RecordType = item.RecordType, Value = item.Value, Remark = item.Remark, CategoryId = item.CategoryId, UserId = item.UserId }); }); _viewModel.DeleteCommand = new DataGridSelectedItemsCommand <RecordModel>(GridRecords, (items) => { // remove in only grid foreach (var item in items.ToList()) { _viewModel.Entities.Remove(item); } }); _viewModel.SaveCommand = new Command(() => { // check valid data if (!ValidateData()) { MessageBox.Show(MultiLangResourceManager.Instance[MultiLangResourceName.SaveFailedMessage], MultiLangResourceManager.Instance[MultiLangResourceName.SaveFailed], MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } foreach (var entity in _viewModel.Entities) { entity.Date = _viewModel.Date; entity.CurrencyId = _viewModel.CurrencyId; entity.StorageId = _viewModel.StorageId; entity.Storage = _viewModel.Storage; entity.CurrencyExchangeRate = _viewModel.CurrencyExchangeRate; if (string.IsNullOrEmpty(entity.Description)) { entity.Description = _viewModel.Description; } if (string.IsNullOrEmpty(entity.Remark)) { entity.Remark = _viewModel.Remark; } _service.Add(entity); } _viewModel.Entities.Clear(); DialogResult = true; this.Close(); }); _viewModel.CancelCommand = new Command(() => { DialogResult = false; this.Close(); }); // init columns _viewModel.RecordTypeList = MultiLangEnumHelper.ToCollection(typeof(RecordType)); // fill defaults _viewModel.Date = DateTime.Now; _viewModel.CurrencyId = _currencies.FirstOrDefault(x => x.IsMain)?.Id ?? _currencies.FirstOrDefault()?.Id ?? 0; _viewModel.Currency = _currencies.FirstOrDefault(x => x.Id == _viewModel.CurrencyId)?.ToReferenceView(); _viewModel.StorageId = _storages.FirstOrDefault(x => x.CurrencyId == _viewModel.CurrencyId)?.Id ?? 0; _viewModel.Storage = _storages.FirstOrDefault(x => x.Id == _viewModel.StorageId)?.ToReferenceView(); _viewModel.Entities.CollectionChanged += (sender, e) => _viewModel.RefreshTotalAmount(); this.DataContext = _viewModel; }
public ActionResult Delete(int id, ChequeViewModel model) { _chequeApplicationService.Delete(id); return(RedirectToAction("Index")); }
public ChequePrincipal() { InitializeComponent(); viewModel = new ChequeViewModel(); this.DataContext = viewModel; }
public HttpResponseMessage SalvarCheque(ChequeViewModel model) { try { var clinica = _cadastroService.ObterClinicaById(base.GetUsuarioLogado().IdClinica); if (clinica == null) { throw new Exception("Não foi possivel recuperar dados da clínica!"); } if (model.IdCheque > 0) { var cheque = _financeiroService.ObterChequePorId(model.IdCheque); if (cheque == null) { throw new Exception("Não foi possivel recuperar dados do cheque!"); } if (model.IdFinanceiro > 0) { var financeiro = _financeiroService.ObterFinanceiroPorId(Convert.ToInt32(model.IdFinanceiro)); if (financeiro == null) { throw new Exception("Não foi possivel recuperar dados de financeiro!"); } cheque.SetFinanceiro(financeiro); } if (model.IdPessoa > 0) { var pessoa = _cadastroService.ObterPessoaPorId(Convert.ToInt32(model.IdPessoa)); if (pessoa == null) { throw new Exception("Não foi possivel recuperar dados de pessoa!"); } cheque.SetPessoa(pessoa); } cheque.SetAgencia(model.Agencia); cheque.SetBanco(model.Banco); cheque.SetClinica(clinica); cheque.SetValor(model.Valor); if (model.BomPara != DateTime.MinValue) { cheque.SetBomPara(Convert.ToDateTime(model.BomPara)); } cheque.SetConta(model.Conta); cheque.SetEmitente(model.Emitente); cheque.SetHistorico(model.Historico); cheque.SetSituacao(model.Situacao); _financeiroService.SalvarCheque(cheque); return(Request.CreateResponse(HttpStatusCode.OK, model)); } else { var cheque = new Cheque(model.Emitente, model.Banco, model.Agencia, model.Conta, model.Situacao, model.Valor, clinica); if (model.IdFinanceiro > 0) { var financeiro = _financeiroService.ObterFinanceiroPorId(Convert.ToInt32(model.IdFinanceiro)); if (financeiro == null) { throw new Exception("Não foi possivel recuperar dados de financeiro!"); } cheque.SetFinanceiro(financeiro); } if (model.IdPessoa > 0) { var pessoa = _cadastroService.ObterPessoaPorId(Convert.ToInt32(model.IdPessoa)); if (pessoa == null) { throw new Exception("Não foi possivel recuperar dados de pessoa!"); } cheque.SetPessoa(pessoa); } if (model.BomPara != DateTime.MinValue) { cheque.SetBomPara(Convert.ToDateTime(model.BomPara)); } cheque.SetHistorico(model.Historico); _financeiroService.SalvarCheque(cheque); return(Request.CreateResponse(HttpStatusCode.OK, model)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } }