예제 #1
0
        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);
 }
예제 #3
0
        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();
            }
        }
예제 #4
0
 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();
 }
예제 #5
0
        //
        // 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));
        }
예제 #6
0
        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));
        }
예제 #7
0
 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);
     }
 }
예제 #8
0
        public Task UpdateAsync(QuotaModel quota)
        {
            _context.Entry(quota).State = EntityState.Modified;

            return(Task.CompletedTask);
        }
예제 #9
0
 public Task InsertAsync(QuotaModel quota)
 {
     return(_context.Quotas.AddAsync(quota));
 }
예제 #10
0
 public QuotaResponse(QuotaModel resource) : base(resource)
 {
 }
예제 #11
0
 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);            
 }