public HttpResponseMessage Report_NewReferralsAggregateByMonth(string token, [FromBody] ReportRequestModel request)
        {
            try
            {
                var    clientId  = context.GetClientIDBySession(token).FirstOrDefault().ClientID.ToString();
                string divisions = "";

                if (clientId == "1934")
                {// -- MEGA HACK !! For Demo purposes only (KAMIL SALAGAN IS TO BLAME FOR THIS)
                    //Override ClientID to allow demo user account to pull data for generating reports without directly linking the account to that ClientID
                    clientId  = "1811";
                    divisions = "1811";
                }
                else
                {
                    divisions = getDivisionsForUser(token, clientId);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(context.Report_NewReferralsAggregateByMonth(token, request.dateFrom, request.dateTo, request.clientService, divisions))));
            }
            catch (Exception e)
            {
                ErrorSignal.FromCurrentContext().Raise(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Exemple #2
0
 public HttpResponseMessage GetClientIDBySession(string Token)
 {
     return(new HttpResponseMessage(HttpStatusCode.OK)
     {
         Content = new StringContent(JsonConvert.SerializeObject(context.GetClientIDBySession(Token)))
     });
 }
Exemple #3
0
        public HttpResponseMessage EmployeeOptionsExternal(string token)
        {
            try
            {
                var         clientId        = con.GetClientIDBySession(token).SingleOrDefault().ClientID;
                var         clientDivisions = con.GetClientDivisions(Convert.ToInt32(clientId));
                List <int?> divisionIds     = clientDivisions.Select(division => division.ClientID).ToList();
                //using the same filter(s) as for claim since user cannot create a claim for an employee they cannot view
                var filters = con.GetFilteredData(token, "Claim").ToList();

                if (filters.FindIndex(f => f.FilterValue == "DIVISION_TREE") > -1)
                {
                    var userProfiles = (from UserProfile in con.User_Profiles
                                        where divisionIds.Contains(UserProfile.ClientID)
                                        select UserProfile).ToList();
                    return(Request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(userProfiles)));
                }
                else if (filters.FindIndex(f => f.FilterValue == "DIVISION") > -1)
                {
                    var userProfiles = (from UserProfile in con.User_Profiles
                                        where UserProfile.ClientID == clientId
                                        select UserProfile).ToList();
                    return(Request.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(userProfiles)));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.Forbidden));
                }
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
Exemple #4
0
        public HttpResponseMessage DownloadLibraryResource(string token, int documentId)
        {
            if (context.CheckIfTokenValid(token) != 10001)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
            try
            {
                var doc = context.Library_Resources.Single(d => d.Id == documentId);

                //if user is internal they have access to all library resources. if they are external they have access to documents that arent client specific or their own client specific documents
                if (doc.SpecificClientID != 1934 && context.IsUserInternal(token) != 1)
                {
                    if (doc.SpecificClientID != null && doc.SpecificClientID != context.GetClientIDBySession(token).Single().ClientID)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Unauthorized));
                    }
                }


                string DocName = doc.DocumentName;
                string DocType = doc.MIMEType;
                string DocExt  = doc.DocExt;
                string DocGuid = doc.StoredGuid;

                HttpContext httpContext = HttpContext.Current;
                FileInfo    file        = new FileInfo(path + DocGuid);
                httpContext.Response.Clear();
                httpContext.Response.ClearHeaders();
                httpContext.Response.AddHeader("Content-Disposition", $"attachment; filename={DocName}");
                //httpContext.Response.AddHeader("Content-length", file.Length.ToString());
                httpContext.Response.ContentType = DocType;
                httpContext.Response.Flush();
                httpContext.Response.TransmitFile(file.FullName);
                httpContext.Response.End();
                return(Request.CreateResponse(HttpStatusCode.OK, DocName + "." + DocExt, Configuration.Formatters.JsonFormatter));
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e);
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
        public HttpResponseMessage UploadClientLogo(string Token)
        {
            var file = HttpContext.Current.Request.Files[0];

            if (file != null)
            {
                //prepend unique identifier to file name
                var fileName = Guid.NewGuid().ToString().Substring(0, 8) + "_" + file.FileName;
                var filePath = $@"\\OSI-DEV01\umbrella\logos\{fileName}";

                try
                {
                    file.SaveAs(filePath);

                    //update the reference to the logo in db
                    using (var context = new OrgSys2017DataContext())
                    {
                        var clientId = context.GetClientIDBySession(Token).SingleOrDefault().ClientID;
                        context.Clients.Where(c => c.ClientID == clientId).SingleOrDefault().LogoPath = fileName;

                        context.SubmitChanges();
                    }

                    return(new HttpResponseMessage(HttpStatusCode.OK));
                }
                catch (Exception e)
                {
                    ExceptionLog.LogException(e);
                    return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                }
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
Exemple #6
0
        public string SaveJSON(string Token, [FromBody] DataList list)
        {
            int        ClaimID       = 0;
            ClaimModel model         = new ClaimModel();
            Connection con           = new Connection();
            var        insertHistory = new List <PKInfo>();

            if (list.contrlData == null)
            {
                return(JsonConvert.SerializeObject(new { Submitted = false }));
            }

            int userId;
            int clientId;
            var txCommitted     = false;
            var archive         = false;
            var claimRefNuValue = list
                                  .contrlData
                                  .Find(x => x.TableName == "Claims")
                                  .Columns
                                  .Find(c => c.ColumnName == "ClaimRefNu")
                                  .Value;

            list.contrlData
            .Find(x => x.TableName == "Claims")
            .Columns
            .Find(c => c.ColumnName == "DateCreation")
            .Value = DateTime.Now.ToString();

            using (var context = new OrgSys2017DataContext()) {
                userId   = context.GetUserIDSession(Token).SingleOrDefault().UserID;
                clientId = context.GetClientIDBySession(Token).SingleOrDefault().ClientID;
            }

            //done outside transaction to prevent escalation to MSDTC
            if (string.IsNullOrEmpty(claimRefNuValue))
            {
                claimRefNuValue = model.UniqueClaimReference("1003");
                list
                .contrlData
                .Find(x => x.TableName == "Claims")
                .Columns
                .Find(c => c.ColumnName == "ClaimRefNu")
                .Value = claimRefNuValue;
            }
            else
            {
                archive = true;
            }

            try
            {
                using (var tx = new TransactionScope())
                {
                    var conString = ConfigurationManager.ConnectionStrings["OrgSysConnectionString"].ToString();
                    using (var connection = new SqlConnection(conString))
                    {
                        connection.Open();
                        foreach (var table in list.contrlData)
                        {
                            if (string.IsNullOrEmpty(table.TableName) | table.Columns.Count == 0 | table.Columns == null)
                            {
                                continue;
                            }

                            var tableRows = table.Columns.GroupBy(x => x.Row).OrderBy(rowNu => rowNu.Key);   //may have multiple rows

                            foreach (var row in tableRows)
                            {
                                var    query             = new PortalQuery(table.TableName);
                                object columnDescription = "";

                                foreach (var col in row)
                                {
                                    object val = String.IsNullOrEmpty(col.Value) ? DBNull.Value : (object)col.Value;

                                    query.AddParameter(col.ColumnName, val);
                                    columnDescription = col.ColumnType;
                                }

                                //
                                if (table.TableName == "Claim_Documents")
                                {
                                    query.AddParameter("ClaimRefNu", claimRefNuValue);
                                    query.AddParameter("UserId", User);
                                    query.AddParameter("Timestamp", DateTime.Now.ToString());
                                }
                                if (table.TableName == "Claim_Dates")
                                {
                                    query.AddParameter("DateDescription", columnDescription);
                                }
                                if (table.TableName == "Claim_Contacts")
                                {
                                    query.AddParameter("ContactType", columnDescription);
                                    query.AddParameter("ClaimRefNu", claimRefNuValue);
                                }
                                if (table.TableName == "Claim_Emp_Schedule")
                                {
                                    query.AddParameter("WeekNo", row.Key);
                                }
                                if (table.TableName == "Claim_Emp_OtherEarnings")
                                {
                                    query.AddParameter("WeekNu", row.Key);
                                }
                                if (table.TableName == "Claim_Employee")
                                {
                                    query.AddParameter("DemEmpID", 1);
                                }
                                if (table.TableName == "Claim_Emp_ContactTypeDetails")
                                {
                                    query.AddParameter("ClaimReference", claimRefNuValue);
                                }
                                if (table.TableName == "Claim_ICDCM_Witness")
                                {
                                    query.AddParameter("Witness", row.Key);
                                    query.AddParameter("ClaimRefNu", claimRefNuValue);
                                }
                                if (table.TableName == "Claim_Injury_Cause")
                                {
                                    query.AddParameter("IsSafe", 1);
                                }
                                if (table.TableName == "Claim_Injury_BodyPart")
                                {
                                    query.AddParameter("Partside", row.FirstOrDefault().Group);
                                }

                                if (table.TableName == "Claims")
                                {
                                    query.AddParameter("Status", list.status);
                                    query.AddParameter("ClientID", clientId);
                                    query.AddParameter("UserSubmitted", userId);
                                    if (!archive)
                                    {
                                        query.AddParameter("Archived", 0);
                                    }
                                }

                                //find fk reference and add as parameter if present
                                var res = insertHistory.Find(x => x.PkTable == table.PKTable);

                                if (res != null)
                                {
                                    query.AddParameter(table.FKName, res.PkValue);
                                }

                                var insertedId = query.ExecuteInsert(connection);
                                insertHistory.Add(new PKInfo(table.TableName, insertedId));

                                if (table.TableName == "Claims")
                                {
                                    ClaimID = insertedId;
                                }
                            }
                        }
                    }

                    tx.Complete();
                    txCommitted = true;
                }

                if (txCommitted && archive)
                {
                    //newClaimRefNu not set means it exists; archive
                    //done outside transaction to prevent escalation to MSDTC
                    model.ArchiveClaim(claimRefNuValue);
                }
            }
            catch (Exception e)
            {
                ExceptionLog.LogException(e);
            }

            return(JsonConvert.SerializeObject(new { Submitted = txCommitted, ClaimID = ClaimID }));
        }