public ActionResult Edit(QuotaModel quotaModel) { try { if (ModelState.IsValid) { Quota quota = db.Quotas.Find(quotaModel.ID); quota.Title = quotaModel.Title; quota.Description = quotaModel.Description; quota.CreatedBy = quotaModel.CreatedBy; quota.DepartmentId = int.Parse(quotaModel.SelectedDepartment); quota.LastModifiedAt = DateTime.Now; quota.CreatedAt = DateTime.Now; quota.LastModifiedBy = User.Identity.Name; db.Entry(quota).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { log.Error(ex.Message, ex); } return(View(quotaModel)); }
private void CompareExpectedResult(QuotaModel result, string subscriptionId) { // Validate response Assert.Equal(string.Format("{0}/{1}", Constants.LocationName, Constants.QuotaName), result.Name); Assert.Equal(Constants.LocationName, result.Location); Assert.Equal(100, result.Properties.CapacityInGB); Assert.Equal(10, result.Properties.NumberOfStorageAccounts); }
public async Task SubtractionQuota(int id_quota) { QuotaModel quotaModel = await db.SetQuotaModels.FirstOrDefaultAsync(u => u.Id == id_quota); if (quotaModel != null) { quotaModel.QuotaCount -= 1; await db.SaveChangesAsync(); } }
public void SaveQuota(int id_p, List <string> list_quota) { foreach (var item in list_quota) { var tmp_string = item.Split('='); string chain_string = tmp_string[0]; QuotaModel tmp_quota = db.SetQuotaModels.FirstOrDefault(u => u.ChainString == chain_string); if (tmp_quota == null) { tmp_quota = new QuotaModel(); tmp_quota.ProjectID = id_p; tmp_quota.ChainString = tmp_string[0]; tmp_quota.QuotaCount = Int32.Parse(tmp_string[1]); db.SetQuotaModels.Add(tmp_quota); } else { tmp_quota.QuotaCount = Int32.Parse(tmp_string[1]); } } db.SaveChanges(); }
// // GET: /Quota/Edit/5 public ActionResult Edit(decimal id = 0) { Quota quota = db.Quotas.Find(id); QuotaModel quotaModel = new QuotaModel(); try { if (quota == null) { return(HttpNotFound()); } quotaModel.ID = quota.ID; quotaModel.Title = quota.Title; quotaModel.Description = quota.Description; quotaModel.CreatedBy = quota.CreatedBy; quotaModel.SelectedDepartment = quota.DepartmentId.ToString(); } catch (Exception ex) { log.Error(ex.Message, ex); } return(View(quotaModel)); }
public ActionResult Create(QuotaModel quotaModel) { if (ModelState.IsValid) { try { Quota quota = new Quota(); quota.Title = quotaModel.Title; quota.Description = quotaModel.Description; quota.CreatedBy = quotaModel.CreatedBy; quota.DepartmentId = int.Parse(quotaModel.SelectedDepartment); quota.LastModifiedAt = DateTime.Now; quota.CreatedAt = DateTime.Now; quota.LastModifiedBy = User.Identity.Name; db.Quotas.Add(quota); if (db.GetValidationErrors().Count() > 0) { //ViewBag.Message } else { db.SaveChanges(); return(RedirectToAction("Index")); } } catch (Exception ex) { ViewBag.Message = ex.Message; log.Error(ex.Message, ex); } } return(View(quotaModel)); }
public void SaveQuota(int id_p, List <string> list_quota) { try { if (list_quota != null) { foreach (var item in list_quota) { var tmp_string = item.Split('='); string chain_string = tmp_string[0]; QuotaModel tmp_quota = db.SetQuotaModels.FirstOrDefault(u => u.ChainString == chain_string); if (tmp_quota == null) { //tmp_quota = new QuotaModel(); //tmp_quota.ProjectID = id_p; //tmp_quota.ChainString = tmp_string[0]; //tmp_quota.QuotaCount = Int32.Parse(tmp_string[1]); db.SetQuotaModels.Add(new QuotaModel() { ProjectID = id_p, ChainString = tmp_string[0], QuotaCount = Int32.Parse(tmp_string[1]) }); } else { tmp_quota.QuotaCount = Int32.Parse(tmp_string[1]); db.Entry(tmp_quota).State = EntityState.Modified; } } db.SaveChanges(); } } catch (Exception e) { Response.AppendToLog(e.StackTrace); } }
public Task UpdateAsync(QuotaModel quota) { _context.Entry(quota).State = EntityState.Modified; return(Task.CompletedTask); }
public Task InsertAsync(QuotaModel quota) { return(_context.Quotas.AddAsync(quota)); }
public QuotaResponse(QuotaModel resource) : base(resource) { }
private void CompareExpectedResult(QuotaModel result, string subscriptionId) { // Validate response Assert.Equal(string.Format("{0}/{1}",Constants.LocationName, Constants.QuotaName), result.Name); Assert.Equal(Constants.LocationName, result.Location); Assert.Equal(100, result.Properties.CapacityInGB); Assert.Equal(10, result.Properties.NumberOfStorageAccounts); }