public LoadMoneyViewModel GetViewModel(Guid UserId) { var client = _userFacade.ClientService.GetClient(UserId); client.LoadDetailsReferences(); var model = new LoadMoneyViewModel { ClientId = client.UserId, UserName = client.UserName, Balance = client.Balance, FullName = string.Format("{0} ({1})", client.GetFullName(), client.UserName), LoadMethods = _transactionService.PaymentMethodService.SelectListPaymentMethods(null) }; return model; }
public bool LoadMoney(LoadMoneyViewModel model) { try { model.NeedUpdate = false; if (model.MethodId == 0) { _validationDictionary.AddError("MethodId", "Please select Peyment Method"); return false; } var client = _userFacade.ClientService.GetClient(model.ClientId); model.Balance = client.Balance; _transactionService.CreateTransaction(model); client.Balance = client.Balance + model.Sum; client.LoadStatusReferences(); if (!client.Status.IsActive && client.Balance > 0) { client.Status = _userFacade.ClientService.StatusService.GetStatus(STATUSES.Active); var secret = _userFacade.SecretService.GetPPPSecret(model.ClientId); secret.Disabled = !client.Status.IsActive; _userFacade.SecretService.EditPPPSecret(secret); model.NeedUpdate = true; } _userFacade.ClientService.EditClient(client); return true; } catch (Exception ex) { _validationDictionary.AddError("_FORM", "Money is not loaded. " + ex.Message); return false; } }
public bool CreateTransaction(LoadMoneyViewModel model) { try { var _ctx = new CurrentContext(); var _transaction = new Transaction { Sum = model.Sum, Comment = model.Comment, Balance = model.Balance, PaymentMethod = PaymentMethodService.GetPaymentMethod(model.MethodId), User = _ctx.CurrentASPUser, Client = _ctx.GetClient(model.ClientId) }; _repository.CreateTransaction(_transaction); return true; } catch (Exception ex) { _validationDictionary.AddError("_FORM", "Transaction is not saved. " + ex.Message); return false; } }
public ActionResult Load(LoadMoneyViewModel model) { if (_facade.LoadMoneyService.LoadMoney(model)) { if (model.NeedUpdate) _sshSecretService.EditPPPSecret(model.ClientId); return View("Index", PrepareIndex(false)); } var loadModel = _facade.LoadMoneyService.GetViewModel(model.ClientId); return View(loadModel); }