public void RequestAccess(Account acct)
        {
            if (u != null)
            {
                var aus = db.AccountUsers.Include(au => au.Account).Include(au => au.User).Where(au => au.AcctId == acct.Id && au.IsOwner).ToList();

                if (aus.Count > 0)
                {
                    var accout = aus.First().Account;

                    Access acs = new Access();
                    acs.AcctId = accout.Id;
                    acs.Uid = u.Id;
                    acs.CreateDt = DateTime.Now;
                    db.Accesses.Add(acs);

                    AccessLog log = new AccessLog();
                    log.AcctId = accout.Id;
                    log.CreateDt = DateTime.Now;
                    log.Uid = u.Id;

                    db.AccessLogs.Add(log);
                    db.SaveChanges();

                    string _basicURL = "http://" + Request.RequestUri.Host + ":" + Request.RequestUri.Port;
                    string htmlLink = _basicURL + "?index=";// +returnId.ToString() + "&token=" + md5;
                    MailMessage msg = new MailMessage();
                    msg.From = new MailAddress("*****@*****.**");
                    foreach (var au in aus)
                    {
                        msg.To.Add(au.User.Email);
                    }
                    msg.CC.Add(u.Email);

                    MailHelper.AddAdminMail(msg);

                    msg.Subject = "Applying access for SAP Box :" + accout.BoxName;

                    msg.Body = "<h3>Hi Owners,</h3>";
                    msg.Body += "<p>" + u.UserName + " is applying the access of SAP Box:" + accout.BoxName + "</p>";
                    msg.Body += "<p>You can grant access for her/him by <a href='" + htmlLink + "'>Click Me</a></p>";
                    msg.Body += "<p>If you don't want to do this,please ignore the mail</p>";
                    msg.IsBodyHtml = true;
                    MailHelper.SendMail(msg);
                }
            }
        }
        public IHttpActionResult GetAccess(Account account)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (u != null)
            {
                Access accs = null;
                var accesses = db.Accesses.Where(c => c.AcctId == account.Id && c.Uid == u.Id).ToList();

                if (accesses.Count > 0)
                {
                    accs = accesses.First();
                }
                else
                {
                    accs = new Access();
                    accs.AcctId = account.Id;
                    accs.CreateDt = DateTime.Now;
                    accs.Uid = u.Id;
                    db.Accesses.Add(accs);

                    AccessLog log = new AccessLog();
                    log.AcctId = account.Id;
                    log.Uid = u.Id;
                    log.CreateDt = DateTime.Now;
                    db.AccessLogs.Add(log);

                    db.SaveChanges();

                }

                var aus = db.AccountUsers.Include(au => au.User).Where(au => au.AcctId == account.Id && au.IsOwner).ToList();
                if (aus.Count > 0)
                {
                    MailMessage msg = new MailMessage();
                    msg.From = new MailAddress("*****@*****.**");
                    foreach (var au in aus)
                    {
                        msg.To.Add(au.User.Email);
                    }
                    msg.CC.Add(u.Email);
                    MailHelper.AddAdminMail(msg);

                    var htmlLink = "http://" + Request.RequestUri.Host + ":" + Request.RequestUri.Port + "/SAPAccounts/SetAccess/" + accs.Id;

                    msg.Subject = "Applying access for SAP Box :" + account.BoxName;

                    msg.Body = "<h3>Hi Owners,</h3>";
                    msg.Body += "<p>" + u.UserName + " is applying the access of SAP Box:" + account.BoxName + "</p>";
                    msg.Body += "<p>You can grant access for her/him by <a href='" + htmlLink + "'>Click Me</a></p>";
                    msg.Body += "<p>If you don't want to do this,please ignore the mail</p>";
                    msg.IsBodyHtml = true;
                    MailHelper.SendMail(msg);
                    return Ok();
                }
            }
            return NotFound();
        }