Beispiel #1
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,BoxName,UserName,Password,Client,ServerAddress,IsAvailable,UpdateDt,IsPrivate")] Account account)
        {
            if (ModelState.IsValid)
            {
                var user = InternalAttribute.GetUser();

                var accoutNum = db.Accounts.Where(c => c.BoxName == account.BoxName).Count();

                if (accoutNum > 0)
                {
                    ViewBag.ErrorMessage = string.Format("The Box {0} has already exist in DB, please choose another one", account.BoxName);
                    return(View(account));
                }


                if (user != null)
                {
                    if (account.Id == 0)
                    {
                        AccountUser au = new AccountUser()
                        {
                            CreateDt  = DateTime.Now,
                            IsOwner   = true,
                            IsPrimary = true,
                            Uid       = user.Id,
                            Account   = account
                        };
                        account.UpdateDt = DateTime.Now;
                        account.AccountUsers.Add(au);
                        db.Accounts.Add(account);
                        db.SaveChanges();
                    }
                    else
                    {
                        var myAct = from at in db.Accounts
                                    join au in db.AccountUsers on at.Id equals au.AcctId
                                    where at.Id == account.Id && au.IsOwner && au.Uid == user.Id
                                    select at;

                        if (myAct.Count() > 0)
                        {
                            db.Entry(account).State = EntityState.Modified;
                            account.UpdateDt        = DateTime.Now;
                            db.SaveChanges();
                        }
                    }
                }

                return(RedirectToAction("MyAccounts"));
            }

            return(View(account));
        }
Beispiel #2
0
        private void WriteAttribute(XmlWriter writer, InternalDataRow dataRow, InternalAttribute dataColumn)
        {
            var field = dataRow[dataColumn];

            if (field == DBNull.Value || object.Equals(field, dataColumn.DefaultValue) == true)
            {
                return;
            }

            var textValue = CremaXmlConvert.ToString(field, dataColumn.DataType);

            if (string.IsNullOrEmpty(textValue) == false)
            {
                writer.WriteStartAttribute(dataColumn.AttributeName);
                writer.WriteValue(textValue);
                writer.WriteEndAttribute();
            }
        }
Beispiel #3
0
        public ActionResult GetAccess()
        {
            List <Account> accounts = new List <Account>();
            User           u        = InternalAttribute.GetUser();

            if (u != null && u.IsValid)
            {
                var myAccounts = from act in db.Accounts
                                 join au in db.AccountUsers on act.Id equals au.AcctId
                                 where au.Uid == u.Id
                                 select act;

                accounts = (from acct in db.Accounts
                            where acct.IsAvailable && !acct.IsPrivate && !myAccounts.Contains(acct)
                            orderby acct.BoxName
                            select acct).ToList();
            }
            return(View(accounts));
        }
Beispiel #4
0
        public ActionResult MyAccounts()
        {
            List <AccountUser> myAccounts = new List <AccountUser>();
            //List<Account> myAccounts = new List<Account>();

            User u = InternalAttribute.GetUser();

            if (u != null && u.IsValid)
            {
                myAccounts = db.AccountUsers.Include(c => c.Account).Where(au => au.Uid == u.Id && au.IsOwner).OrderBy(a => a.Account.BoxName).ToList();
                //myAccounts = (from act in db.Accounts
                //              join au in db.AccountUsers on act.Id equals au.AcctId
                //              where au.Uid == u.Id && au.IsOwner
                //              select act).ToList();
            }


            return(View(myAccounts));
        }
        public SAPBaseController()
        {
            var session = System.Web.HttpContext.Current.Session;


            if (session["IsInnerUser"] == null)
            {
                var user = InternalAttribute.GetUser();
                if (user == null)
                {
                    session["IsInnerUser"] = false;
                }
                else
                {
                    session["IsInnerUser"] = true;
                }
            }

            ViewBag.IsValid = bool.Parse(session["IsInnerUser"].ToString());
        }
Beispiel #6
0
        // GET: SAPAccounts/Details/5
        public ActionResult Details(int id)
        {
            var user = InternalAttribute.GetUser();

            if (user == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            IEnumerable <AccountUser> accounts = db.AccountUsers.Include(c => c.User).Include(c => c.Account).Where(c => c.AcctId == id).ToList();

            var account = new Account();

            if (accounts.Count() > 0)
            {
                account = accounts.First().Account;
            }


            return(View(account));
        }
Beispiel #7
0
        // GET: SAPAccounts
        public ActionResult Index()
        {
            List <Account> myAccounts = new List <Account>();

            User u = InternalAttribute.GetUser();



            if (u != null && u.IsValid)
            {
                myAccounts = (from act in db.Accounts
                              join au in db.AccountUsers on act.Id equals au.AcctId
                              where act.IsAvailable &&
                              au.Uid == u.Id
                              orderby act.BoxName
                              select act).ToList();
            }


            return(View(myAccounts));
        }
        private ReportInfo getReports(MyReportFilter Filter, int page)
        {
            ReportInfo ri = new ReportInfo();

            ri.Filter = Filter;
            var u = InternalAttribute.GetUser();

            if (u != null)
            {
                ri.IsVaildUser = true;
            }


            string user = User.Identity.Name.Trim().ToLower();

            ViewBag.Message = "";

            using (var db = new SAPTestContext())
            {
                IQueryable <Report> reportQuery = db.Reports.Include(r => r.Asset.Release.Project).Include(r => r.User);
                if (Filter.qs != null)
                {
                    reportQuery      = reportQuery.Where(r => r.TestName.Contains(Filter.qs));
                    ViewBag.Message += " Test Name contains:" + Filter.qs + "\n";
                }
                if (Filter.Pid > 0)
                {
                    reportQuery      = reportQuery.Where(r => r.Asset.Release.Project.Id == Filter.Pid);
                    ViewBag.Message += "Project:" + db.Projects.Find(Filter.Pid).Name + "\n";
                }
                if (Filter.Rid > 0)
                {
                    reportQuery      = reportQuery.Where(r => r.Asset.Release.Id == Filter.Rid);
                    ViewBag.Message += "Release:" + db.Releases.Find(Filter.Rid).Name + "\n";
                }
                if (Filter.Aid > 0)
                {
                    reportQuery      = reportQuery.Where(r => r.Asset.Id == Filter.Aid);
                    ViewBag.Message += "Asset:" + db.Assets.Find(Filter.Aid).Name + "\n";
                }


                ri.TotalReportNum = reportQuery.Count();

                if (Filter.isMyReport)
                {
                    ViewBag.PageCount = Math.Ceiling((double)ri.MyReportNum / _numInPage);
                    ri.IsMyReport     = true;

                    reportQuery    = reportQuery.Where(r => r.Executor.Trim().ToLower() == user);
                    ri.MyReportNum = reportQuery.Count();
                    //ri.Reports = reportQuery.Where(r => r.Executor.Trim().ToLower() == user).OrderByDescending(c => c.SubmitDt).Skip(_numInPage * (page - 1)).Take(_numInPage).ToList();
                }
                else
                {
                    ri.MyReportNum = reportQuery.Where(r => r.Executor.Trim().ToLower() == user).Count();
                    //ri.Reports = reportQuery.OrderByDescending(c => c.SubmitDt).Skip(_numInPage * (page - 1)).Take(_numInPage).ToList();
                    ViewBag.PageCount = Math.Ceiling((double)ri.TotalReportNum / _numInPage);
                }



                if (Filter.Sort == -1)
                {
                    reportQuery = reportQuery.OrderByDescending(c => c.SubmitDt);
                }
                else if (Filter.Sort == 0)
                {
                    reportQuery = reportQuery.OrderBy(c => c.CaseNum).ThenByDescending(c => c.SubmitDt);
                }
                else
                {
                    reportQuery = reportQuery.OrderByDescending(c => c.CaseNum).ThenByDescending(c => c.SubmitDt);
                }

                ri.Reports = reportQuery.Skip(_numInPage * (page - 1)).Take(_numInPage).ToList();
            }


            ViewBag.CurrentPage = page;

            return(ri);
        }
        public ActionResult Upload()
        {
            var u = InternalAttribute.GetUser();

            if (u != null)
            {
                HttpPostedFileBase file         = Request.Files["file"];
                string             guid         = Guid.NewGuid().ToString();
                string             path         = HttpContext.Server.MapPath("/Report1/Temp");
                string             backupPath   = HttpContext.Server.MapPath("/Report1/Backup");
                string             reportFolder = HttpContext.Server.MapPath("/Report1/ReportFiles");

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                if (!Directory.Exists(backupPath))
                {
                    Directory.CreateDirectory(backupPath);
                }

                string fileName = Path.Combine(path, guid + "_" + file.FileName.Split('\\').Last());
                string type     = file.ContentType;
                file.SaveAs(fileName);
                FileInfo fi = new FileInfo(fileName);
                int      atId;
                try
                {
                    if (string.Compare(fi.Extension, ".zip", true) == 0 && int.TryParse(Request.Form["asset"], out atId) && atId > 0)
                    {
                        ZipFile.ExtractToDirectory(fileName, Path.Combine(reportFolder, guid));
                        string reportFile = Path.Combine(reportFolder, guid, "report.xml");
                        if (System.IO.File.Exists(reportFile))
                        {
                            XmlDocument xDoc = new XmlDocument();
                            xDoc.Load(reportFile);
                            Report rp = ReportReader.ReadReport(xDoc);
                            rp.Executor = User.Identity.Name;
                            rp.Uid      = u.Id;
                            using (var db = new SAPTestContext())
                            {
                                rp.Url = guid;
                                // "/Report1/ReportFiles/" + guid + "/report.xml";
                                Asset at = db.Assets.Find(atId);
                                if (at != null)
                                {
                                    rp.Asset = at;
                                }
                                db.Reports.Add(rp);
                                db.SaveChanges();
                            }
                            ViewBag.Flag = true;
                        }
                        else
                        {
                            Directory.Delete(Path.Combine(reportFolder, guid), true);
                            ViewBag.Flag = false;
                        }
                    }
                    else
                    {
                        ViewBag.Flag = false;
                    }
                    System.IO.File.Move(fileName, Path.Combine(backupPath, guid + ".zip"));
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMsg = ex.Message;
                    fi.Delete();
                    if (Directory.Exists(Path.Combine(reportFolder, guid)))
                    {
                        Directory.Delete(Path.Combine(reportFolder, guid), true);
                    }
                    throw new Exception();
                }
                MyReportFilter filter = new MyReportFilter();
                filter.isMyReport = true;
                return(RedirectToAction("Index", filter));
            }
            return(RedirectToAction("Index"));
        }
Beispiel #10
0
        public ActionResult SetAccess(int id)
        {
            var u = InternalAttribute.GetUser();

            if (u != null)
            {
                var access = db.Accesses.Where(c => c.Id == id).FirstOrDefault();
                if (access != null)
                {
                    var aus = db.AccountUsers.Include(a => a.User).Include(a => a.Account).Where(a => a.AcctId == access.AcctId && a.IsOwner).ToList();

                    if (aus.Exists(a => a.Uid == u.Id))
                    {
                        AccountUser newAu = new AccountUser();
                        newAu.Uid      = access.Uid;
                        newAu.AcctId   = access.AcctId;
                        newAu.CreateDt = DateTime.Now;

                        db.AccountUsers.Add(newAu);
                        db.Accesses.Remove(access);
                        db.SaveChanges();



                        var targetUser = db.Users.Find(access.Uid);
                        ViewBag.UserName = targetUser.UserName;
                        ViewBag.BoxName  = aus.First().Account.BoxName;

                        MailMessage msg = new MailMessage();
                        msg.From = new MailAddress("*****@*****.**");



                        msg.To.Add(targetUser.Email);


                        foreach (var au in aus)
                        {
                            msg.CC.Add(au.User.Email);
                        }

                        MailHelper.AddAdminMail(msg);

                        msg.Subject    = "You now have access to SAP Box:" + aus.First().Account.BoxName;
                        msg.Body       = "<p>Hi,</p>";
                        msg.Body      += "<P>" + u.UserName + " has granted the access to SAP Box for you</p>";
                        msg.IsBodyHtml = true;
                        MailHelper.SendMail(msg);
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "You don't have permisson to do this";
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = "Can not find the request.";
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Invaild User";
            }

            return(View());
        }