Example #1
0
        public ActionResult OfficeBillEdit()
        {
            var officeRole = _db.Roles.FirstOrDefault(r => r.Name.Contains("Офис"));

            var model = new OfficeBillEditViewModel
            {
                _5kBillSum    = _db.SettingsValues.FirstOrDefault(sv => sv.Key == "5kBillSum").Value,
                _2kBillSum    = _db.SettingsValues.FirstOrDefault(sv => sv.Key == "2kBillSum").Value,
                OtherSum      = _db.SettingsValues.FirstOrDefault(sv => sv.Key == "OtherSum").Value,
                OfficeBalance = _db.Users.Where(u => u.Roles.Any(r => r.RoleId == officeRole.Id)).Sum(u => u.Balance)
            };

            return(PartialView(model));
        }
Example #2
0
        public async Task <ActionResult> OfficeBillEdit(OfficeBillEditViewModel model)
        {
            var nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();

            nfi.NumberGroupSeparator = " ";

            var settingsValue = _db.SettingsValues.FirstOrDefault(sv => sv.Key == "5kBillSum");

            settingsValue.Value = decimal.Parse(model._5kBillSum.Replace(" ", string.Empty), CultureInfo.InvariantCulture).ToString("#,0", nfi);

            settingsValue       = _db.SettingsValues.FirstOrDefault(sv => sv.Key == "2kBillSum");
            settingsValue.Value = decimal.Parse(model._2kBillSum.Replace(" ", string.Empty), CultureInfo.InvariantCulture).ToString("#,0", nfi);

            settingsValue       = _db.SettingsValues.FirstOrDefault(sv => sv.Key == "OtherSum");
            settingsValue.Value = decimal.Parse(model.OtherSum.Replace(" ", string.Empty), CultureInfo.InvariantCulture).ToString("#,0", nfi);

            await _db.SaveChangesAsync();

            return(RedirectToAction("OfficeBillInfo"));
        }