public bool Add(DolarDto dolar) { if (!_dolars.GetAll().Any(i => i.Users.Login == dolar.Login) && dolar.Value>=0) { try { _dolars.Add(new Dolars { User_ID = _users.GetAll().First(i => i.ID == dolar.User_ID).ID, Value = dolar.Value }); _unitOfWork.Commit(); return true; } catch (Exception) { return false; } } return false; }
public DolarDto UserDolar() { DolarDto dolar = new DolarDto(); foreach (var item in _user.GetAll().Where(i => i.ID == dolar.User_ID)) { dolar.Value = _dolar.GetAll().First(i => i.User_ID == item.ID).Value; } return dolar; }
public bool Update(DolarDto dolar) { if (_dolars.GetAll().Any(i => i.Users.Login == dolar.Login) && dolar.Value >= 0) { foreach (var item in _dolars.GetAll().Where(i => i.ID == dolar.ID)) { item.User_ID = _users.GetAll().First(i => i.Login == dolar.Login).ID; item.Value = dolar.Value; } _unitOfWork.Commit(); return true; } return false; }
public ActionResult AddDolar(DolarViewModel dolarModel) { List<string> errors; if (Session["val"] != null) { errors = ((string[])Session["val"]).ToList(); } else { errors = new List<string>(); } DolarDto _dolarDto = new DolarDto(); _dolarDto.User_ID = dolarModel.viewModel.User_ID; _dolarDto.Login = dolarModel.viewModel.User_Login; _dolarDto.Value = dolarModel.viewModel.DolarValue; if (_dolarService.Add(_dolarDto)) { errors.Add("Dodano pieniądze."); } else { errors.Add("Błąd. Spróbuj ponownie."); } Session["val"] = errors.ToArray<string>(); return RedirectToAction("Admin"); }