コード例 #1
0
        public IHttpActionResult GetStockRequests(string client, int?project, DateTime?fromDate, DateTime?toDate, string status, int?page, int?count)
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var user       = "";
                    int?TotalCount = 0;
                    var employeeId = User.Identity.GetUserId();
                    var emp        = db.Employees.Where(x => x.AspNetUserId == employeeId).FirstOrDefault();
                    if (emp != null)
                    {
                        if (emp.Role_Id != "8")
                        {
                            user = User.Identity.GetUserId();
                        }
                        else
                        {
                            user = null;
                        }
                    }
                    else
                    {
                        user = null;
                    }
                    var stockRequests = db.GetStockRequests(user, client, project, fromDate, toDate, status, page, count).ToList();

                    var stockMangers = db.StockManagers.ToList();

                    var exists = stockMangers.Find(x => x.AspNetUserId == user);

                    if (exists != null)
                    {
                        var otherRequests = db.GetStockRequests(null, client, project, fromDate, toDate, "Approved", page, count).ToList();

                        for (int i = 0; i < otherRequests.Count(); i++)
                        {
                            stockRequests.Add(otherRequests[i]);
                        }
                    }

                    if (stockRequests.Count() > 0)
                    {
                        TotalCount = stockRequests.FirstOrDefault().TotalCount;
                    }
                    return(Content(HttpStatusCode.OK, new { stockRequests, TotalCount }));
                }
            }
            catch (Exception ex)
            {
                new Error().logAPIError(System.Reflection.MethodBase.GetCurrentMethod().Name, ex.ToString(), ex.StackTrace);
                return(Content(HttpStatusCode.InternalServerError, "An error occured, please try again later"));
            }
        }