public ActionResult Handle(int?id, string result)
        {
            if (id == null)
            {
                return(RedirectToAction("HandleApplication"));
            }
            ApplyRecord record = db.ApplyRecords.Find(id);

            if (record == null)
            {
                return(RedirectToAction("HandleApplication"));
            }
            record.Admin      = User.Identity.Name;
            record.States     = result;
            record.HandleDate = DateTime.Now;
            if (result == "Approve")
            {
                var server = db.Servers.Find(record.ServerId);
                var user   = db.UserServers.Find(record.Applicant);
                if (user == null)
                {
                    user         = new UserServer();
                    user.UserId  = record.Applicant;
                    user.Servers = new List <Server>();
                    user.Servers.Add(server);
                    db.UserServers.Add(user);
                }
                else
                {
                    user.Servers.Add(server);
                }
                server.State = "Rented";

                ServerRentalRecord RentalRecord = new ServerRentalRecord();
                RentalRecord.ServerId = record.ServerId;
                RentalRecord.From     = DateTime.Now;
                RentalRecord.IsActive = true;
                RentalRecord.Renter   = User.Identity.Name;
                db.ServerRentalRecords.Add(RentalRecord);
            }

            db.SaveChanges();
            if (result == "Approve")
            {
                var OtherApply = db.ApplyRecords.Where(x => x.ServerId == record.ServerId && x.States == "Active").ToList();
                foreach (var other in OtherApply)
                {
                    other.States = "Decline";
                }
            }
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #2
0
        public ActionResult Apply(string Id)
        {
            ApplyRecord ApplyRecord = new ApplyRecord();

            ApplyRecord.Applicant  = User.Identity.Name;
            ApplyRecord.CreateDate = DateTime.Now;
            ApplyRecord.ServerId   = Id;
            ApplyRecord.States     = "Active";
            db.ApplyRecords.Add(ApplyRecord);
            db.SaveChanges();

            return(RedirectToAction("MyServer"));
        }
Example #3
0
        public ActionResult Apply(string[] ServerId)
        {
            if (ServerId != null)
            {
                foreach (var id in ServerId)
                {
                    ApplyRecord ApplyRecord = new ApplyRecord();
                    ApplyRecord.Applicant  = User.Identity.Name;
                    ApplyRecord.CreateDate = DateTime.Now;
                    ApplyRecord.ServerId   = id;
                    ApplyRecord.States     = "Active";
                    db.ApplyRecords.Add(ApplyRecord);
                }
                db.SaveChanges();
            }

            return(RedirectToAction("MyServer"));
        }