예제 #1
0
        public IHttpActionResult GetEmpDocuments(int EmpId, string category, DateTime?uploadDate, DateTime?documentDate, string notes, string keyWords, int page, int count, string sortCol, string sortDir)
        {
            try
            {
                using (MaxMasterDbEntities db = new MaxMasterDbEntities())
                {
                    var employeeDocumnets = db.GetEmployeeDocuments(EmpId, category, uploadDate, documentDate, notes, keyWords, page, count, sortCol, sortDir).ToList();

                    if (employeeDocumnets.Count > 0)
                    {
                        var EmployeeName = employeeDocumnets.FirstOrDefault().EmployeeName;
                        var EmpNumber    = employeeDocumnets.FirstOrDefault().EmployeeNumber;
                        var totalCount   = employeeDocumnets.FirstOrDefault().TotalCount;
                        return(Content(HttpStatusCode.OK, new { employeeDocumnets, EmployeeName, EmpNumber, totalCount }));
                    }

                    else
                    {
                        var totalCount   = 0;
                        var EmployeeName = db.Employees.Where(x => x.Id == EmpId).Select(x => x.FirstName + " " + x.LastName).FirstOrDefault();
                        var EmpNumber    = db.Employees.Where(x => x.Id == EmpId).Select(x => x.EmployeeNumber).FirstOrDefault();
                        return(Content(HttpStatusCode.OK, new { employeeDocumnets, EmployeeName, EmpNumber, totalCount }));
                    }


                    //EmployeeDocumentModel empDoc = new EmployeeDocumentModel();
                    //empDoc.EmployeeName = employeeDocumnets.FirstOrDefault().EmployeeName;
                    //empDoc.EmployeeNumber = employeeDocumnets.FirstOrDefault().EmployeeNumber;
                    //var totalCount = employeeDocumnets.FirstOrDefault().TotalCount;

                    //foreach (var doc in employeeDocumnets)
                    //{
                    //    var documents = new DocumentModel();
                    //    documents.Category = doc.Category;
                    //    documents.Keywords = doc.Keywords;
                    //    documents.Notes = doc.Notes;
                    //    documents.UploadDate =doc.UploadDate.ToString();
                    //    documents.DocumentDate = doc.DocumentDate.ToString();
                    //    empDoc.Documents.Add(documents);
                    //}
                }
            }
            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"));
            }
        }