コード例 #1
0
        public ActionResult AdjustQuota(FormCollection collection)
        {
            try
            {
                Entities ctx = new Entities();

                OrderEntity oe = new OrderEntity();

                oe.User       = this.User.Identity.Name;
                oe.Type       = "AdjustQuota";
                oe.Id         = Guid.NewGuid();
                oe.CreateDate = DateTime.Now;
                oe.Status     = "Open";
                oe.Approval   = "AutoApproved";
                ctx.AddToOrderEntities(oe);
                ctx.SaveChanges();


                QuotaEntity q = new QuotaEntity();
                q.Id    = Guid.NewGuid();
                q.Name  = collection["Name"];
                q.Quota = collection["Quota"];
                q.Order = oe.Id;
                ctx.AddToQuotaEntities(q);
                ctx.SaveChanges();


                Logger.LogMsg(String.Format("Quota {0} queued", collection["Name"]), this.User.Identity.Name);
                ViewData["Status"] = "Request successfully queued";
            }
            catch (Exception ex)
            {
                Logger.LogMsg(ex.Message, this.User.Identity.Name);
                ViewData["Status"] = "Error queuing Request";
            }
            return(RedirectToAction("CreateSiteCollectionSuccess", "Action"));
        }
コード例 #2
0
        public async Task <QuotaEntity> CreateOrUpdateQuotaAsync(
            string engagementAccount,
            string quotaName,
            int quota)
        {
            using (var ctx = new AdminEntities(this.connectionString))
            {
                var existing = await ctx.Quotas.SingleOrDefaultAsync(
                    q => q.AccountName == engagementAccount &&
                    q.QuotaName == quotaName);

                var now = DateTime.UtcNow;
                if (existing != null)
                {
                    existing.Quota           = quota;
                    existing.LastUpdatedTime = now;
                }
                else
                {
                    existing = new QuotaEntity
                    {
                        AccountName     = engagementAccount,
                        QuotaName       = quotaName,
                        Remaining       = quota,
                        Quota           = quota,
                        CreatedTime     = now,
                        LastUpdatedTime = now
                    };
                    ctx.Quotas.Add(existing);
                }

                await ctx.SaveChangesAsync();

                return(existing);
            }
        }