Пример #1
1
 public int SaveComplaint(complaintItem complaint)
 {
     asynSaveImage = new SaveImageBytes(ImageController.SavePicture);
     try
     {
         context = new SocialCopsEntities();
         // Add Log
         logger.LogMethod("ENTER","SaveComplaint","Userid/" + complaint.userId.ToString()+ "/ started SaveComplaint", null);
         // New Complaint
         Complaint temp = new Complaint();
         temp = complaintItem.convertComplaint(complaint);
         //Add a new Complaint
         context.Complaints.Add(temp);
         context.SaveChanges();
         //Image Upload Async
         byte[] image = complaint.ImageByte;
         if (image.Length > 0)
         {
             IAsyncResult result = asynSaveImage.BeginInvoke(image, temp.complaintId.ToString(), new AsyncCallback(FinishImageUpload), asynSaveImage);
         }
         // Exit Log
         logger.LogMethod("EXIT", "SaveComplaint", "Userid/" + complaint.userId.ToString() + "/ finished SaveComplaint", null);
         return temp.complaintId;
     }
     catch (Exception ex)
     {
         logger.LogMethod("ERROR", "SaveComplaint", "Userid/" + complaint.userId.ToString() + "/ " + ex.ToString(), null);
         error.Result = false;
         error.ErrorMessage = "unforeseen error occured. Please try later.";
         error.ErrorDetails = ex.ToString();
         throw new FaultException<Bug>(error, ex.ToString());
     }
 }
Пример #2
0
        public authorityItem[] GetAuthsBySolved(string num)
        {
            try
            {
                logger.LogMethod("jo", "GetAuthsBySolved", "Enter");
                List <authorityItem> list = new List <authorityItem>();
                key = num + "GetAuthsBySolved";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List <authorityItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetAuthsBySolved", "Cache found");
                        return(list.ToArray());
                    }
                }
                list    = new List <authorityItem>();
                context = new SocialCopsEntities();
                int pts = Convert.ToInt32(num);
                List <Authority> auths = (from a
                                          in context.Authorities
                                          where a.numResolved >= pts
                                          orderby a.numResolved descending
                                          select a).ToList();

                foreach (Authority auth in auths)
                {
                    authorityItem temp = new authorityItem();
                    temp.authId      = auth.authId;
                    temp.authName    = auth.authName;
                    temp.authAddress = auth.authAddress;
                    temp.email       = auth.email;
                    temp.phone       = Convert.ToInt32(auth.phone);
                    temp.numPending  = (int)auth.numPending;
                    temp.numResolved = (int)auth.numResolved;
                    temp.latitude    = temp.latitude;
                    temp.longitude   = temp.longitude;
                    temp.website     = auth.website;
                    temp.profilePic  = auth.profilePic;
                    temp.flag        = (int)auth.flag;
                    temp.date        = auth.date;
                    temp.city        = auth.city;
                    temp.state       = auth.state;
                    temp.country     = auth.country;
                    temp.pincode     = auth.pincode;
                    list.Add(temp);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("jo", "GetAuthsBySolved", "Exit");
                return(list.ToArray());
            }
            catch (Exception ex)
            {
                error.ErrorDetails = ex.Message.ToString();
                error.ErrorMessage = "Something happened. Sorry.";
                error.Result       = false;
                logger.LogMethod("jo", "GetAuthsBySolved", ex.Message.ToString());
                throw new FaultException <Bug>(error, ex.Message.ToString());
            }
        }
Пример #3
0
 // To lodge Social Complaints
 #region SaveComplaint
 public int SaveComplaint(complaintItem complaint)
 {
     asynSaveImage = new SaveImageBytes(ImageController.SavePicture);
     try
     {
         context = new SocialCopsEntities();
         // Add Log
         logger.LogMethod("ENTER", "SaveComplaint", "Userid/" + complaint.userId.ToString() + "/ started SaveComplaint", null);
         // New Complaint
         Complaint temp = new Complaint();
         temp = complaintItem.convertComplaint(complaint);
         //Add a new Complaint
         context.Complaints.Add(temp);
         context.SaveChanges();
         //Image Upload Async
         byte[] image = complaint.ImageByte;
         if (image.Length > 0)
         {
             IAsyncResult result = asynSaveImage.BeginInvoke(image, temp.complaintId.ToString(), new AsyncCallback(FinishImageUpload), asynSaveImage);
         }
         // Exit Log
         logger.LogMethod("EXIT", "SaveComplaint", "Userid/" + complaint.userId.ToString() + "/ finished SaveComplaint", null);
         return(temp.complaintId);
     }
     catch (Exception ex)
     {
         logger.LogMethod("ERROR", "SaveComplaint", "Userid/" + complaint.userId.ToString() + "/ " + ex.ToString(), null);
         error.Result       = false;
         error.ErrorMessage = "unforeseen error occured. Please try later.";
         error.ErrorDetails = ex.ToString();
         throw new FaultException <Bug>(error, ex.ToString());
     }
 }
Пример #4
0
        public muteAuthorityItem[] GetMuteAuthsById(string id)
        {
            try
            {
                logger.LogMethod("jo", "GetMuteAuthsById", "Enter");
                List <muteAuthorityItem> list = new List <muteAuthorityItem>();
                key = id.ToString() + "GetMuteAuthsById";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List <muteAuthorityItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetMuteAuthsById", "Cache found");
                        return(list.ToArray());
                    }
                }
                list    = new List <muteAuthorityItem>();
                context = new SocialCopsEntities();
                int mid = Convert.ToInt32(id);
                List <MuteAuthority> muteAuths = (from a
                                                  in context.MuteAuthorities
                                                  where a.muteAuthId == mid
                                                  orderby a.date descending
                                                  select a).ToList();

                foreach (MuteAuthority auth in muteAuths)
                {
                    muteAuthorityItem temp = new muteAuthorityItem();
                    temp.muteAuthId      = auth.muteAuthId;
                    temp.muteAuthName    = auth.muteAuthName;
                    temp.muteAuthAddress = auth.muteAuthAddress;
                    temp.city            = auth.city;
                    temp.state           = auth.state;
                    temp.country         = auth.country;
                    temp.email           = auth.email;
                    temp.phone           = auth.phone;
                    temp.latitude        = (float)auth.latitude;
                    temp.longitude       = (float)auth.longitude;
                    temp.website         = auth.website;
                    temp.pic             = auth.pic;
                    temp.date            = (DateTime)auth.date;
                    temp.flag            = (int)auth.flag;
                    temp.pincode         = auth.pincode;
                    list.Add(temp);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("jo", "GetMuteAuthsById", "Exit");
                return(list.ToArray());
            }
            catch (Exception ex)
            {
                error.ErrorDetails = ex.Message.ToString();
                error.ErrorMessage = "Something happened. Sorry.";
                error.Result       = false;
                logger.LogMethod("jo", "GetMuteAuthsById", ex.Message.ToString());
                throw new FaultException <Bug>(error, ex.Message.ToString());
            }
        }
Пример #5
0
        public muteAuthorityItem[] GetMuteAuths()
        {
            try
            {
                logger.LogMethod("jo", "GetMuteAuths", "Enter");
                List<muteAuthorityItem> list = new List<muteAuthorityItem>();
                key = "GetMuteAuths";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List<muteAuthorityItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetMuteAuths", "Cache found");
                        return list.ToArray();
                    }
                }
                list = new List<muteAuthorityItem>();
                context = new SocialCopsEntities();
                List<MuteAuthority> muteAuths = (from a
                                         in context.MuteAuthorities
                                         orderby a.date descending
                                         select a).ToList();

                foreach (MuteAuthority auth in muteAuths)
                {
                    muteAuthorityItem temp = new muteAuthorityItem();
                    temp.muteAuthId = auth.muteAuthId;
                    temp.muteAuthName = auth.muteAuthName;
                    temp.muteAuthAddress = auth.muteAuthAddress;
                    temp.city = auth.city;
                    temp.state = auth.state;
                    temp.country = auth.country;
                    temp.email = auth.email;
                    temp.phone = auth.phone;
                    temp.latitude = (float)auth.latitude;
                    temp.longitude = (float)auth.longitude;
                    temp.website = auth.website;
                    temp.pic = auth.pic;
                    temp.date = (DateTime)auth.date;
                    temp.flag = (int)auth.flag;
                    temp.pincode = auth.pincode;
                    list.Add(temp);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("jo", "GetMuteAuths", "Exit");
                return list.ToArray();

            }
            catch (Exception ex)
            {
                error.ErrorDetails = ex.Message.ToString();
                error.ErrorMessage = "Something happened. Sorry.";
                error.Result = false;
                logger.LogMethod("jo", "GetMuteAuths", ex.Message.ToString());
                throw new FaultException<Bug>(error, ex.Message.ToString());
            }
        }
Пример #6
0
        public int SaveMuteAuth(muteAuthorityItem muteAuth)
        {
            try
            {
                logger.LogMethod("jo", "SaveMuteAuth", "Enter", null);
                context = new SocialCopsEntities();
                MuteAuthority temp = new MuteAuthority();

                List <MuteAuthority> muteAuths = (from m
                                                  in context.MuteAuthorities
                                                  where m.email == muteAuth.email
                                                  select m).ToList();

                if (muteAuths.Count > 0)
                {
                    logger.LogMethod("jo", "SaveMuteAuth", "Invalid Sign-up. Email address already exists.");
                    error.ErrorDetails = "Email address already exists.";
                    error.Result       = false;
                    error.ErrorMessage = "Email address already exists. Cannot register again.";
                    throw new WebFaultException <Bug>(error, System.Net.HttpStatusCode.NotAcceptable);
                }

                temp.muteAuthName    = muteAuth.muteAuthName;
                temp.muteAuthAddress = muteAuth.muteAuthAddress;
                temp.city            = muteAuth.city;
                temp.state           = muteAuth.state;
                temp.country         = muteAuth.country;
                temp.email           = muteAuth.email;
                temp.phone           = muteAuth.phone;
                temp.latitude        = muteAuth.latitude;
                temp.longitude       = muteAuth.longitude;
                temp.website         = muteAuth.website;
                temp.pic             = muteAuth.pic;
                temp.date            = System.DateTime.Now;
                temp.flag            = muteAuth.flag;
                temp.pincode         = muteAuth.pincode;

                context.MuteAuthorities.Add(temp);
                context.SaveChanges();
                logger.LogMethod("jo", "SaveMuteAuth", "Exit", null);
                //userItem u = (userItem)context.Entry(temp);
                return(temp.muteAuthId);
            }
            catch (WebFaultException <Bug> ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                error.Result       = false;
                error.ErrorMessage = "unforeseen error occured. Please try later.";
                error.ErrorDetails = ex.ToString();
                throw new FaultException <Bug>(error, ex.ToString());
            }
        }
Пример #7
0
 public Log LogMethod(string username, string method, string message, params object[] parameters)
 {
     context        = new SocialCopsEntities();
     log.username   = username;
     log.logDetails = method;
     log.logMessage = message;
     log.date       = DateTime.Now;
     context.Logs.Add(log);
     context.SaveChanges();
     return(log);
 }
Пример #8
0
 public Log LogMethod(string username,string method,string message,params object[] parameters)
 {
     context = new SocialCopsEntities();
     log.username = username;
     log.logDetails = method;
     log.logMessage = message;
     log.date = DateTime.Now;
     context.Logs.Add(log);
     context.SaveChanges();
     return log;
 }
Пример #9
0
        //GetComplaintsByid
        #region GetComplaintsById/{id}
        public complaintItem GetComplaintsById(string id)
        {
            complaintItem temp = new complaintItem();

            key = id + "GetComplaints";
            try
            {
                logger.LogMethod("DEBUG", "GetComplaints/{id}", id + "/ started GetComplaints/{id}", null);
                context = new SocialCopsEntities();
                if (CachingConfig.CachingEnabled)
                {
                    temp = (complaintItem)WCFCache.Current[key];
                    if (temp != null)
                    {
                        logger.LogMethod("CACHE", "GetComplaints/{id}", id + "/ Cache Found - finished GetComplaints/{id}", null);
                        return(temp);
                    }
                }
                int cId = Convert.ToInt32(id);
                List <Complaint> complaints = (from c
                                               in context.Complaints
                                               where c.complaintId == cId
                                               select c).ToList();
                temp = new complaintItem();
                if (complaints.Count == 0)
                {
                    error.Result       = false;
                    error.ErrorMessage = "Invalid request. There is no complaint of the given id.";
                    logger.LogMethod("ERROR", "GetComplaints/{id}", id + "/ Invalid request. There is no complaint of the given id.", null);
                    throw new FaultException <Bug>(error);
                }


                foreach (Complaint complaint in complaints)
                {
                    temp = complaintItem.convertComplaint(complaint);
                }
                Cache.Cache.AddToCache(key, temp);
                logger.LogMethod("DEBUG", "GetComplaints/{id}", id + "/ finished GetComplaints/{id}", null);
                return(temp);
            }
            catch (Exception ex)
            {
                error.Result       = false;
                error.ErrorMessage = "unforeseen error occured. Please try again later";
                logger.LogMethod("ERROR", "GetComplaints/{id}", id + "/ " + ex.Message);
                throw new FaultException <Bug>(error, ex.ToString());
            }
        }
Пример #10
0
        public spamItem[] GetSpam(string complaintId)
        {
            try
            {
                logger.LogMethod("DEBUG", "GetSpam/{complaintId}", complaintId + "/ started GetSpam/{complaintId}", null);

                List <spamItem> list = new List <spamItem>();
                key = complaintId + "GetSpam";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List <spamItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("CACHE", "GetSpam/{complaintId}", complaintId + "/ Cache Found - GetSpam/{complaintId}", null);
                        return(list.ToArray());
                    }
                }
                list    = new List <spamItem>();
                context = new SocialCopsEntities();
                //Retrieving records from the database
                int         cid   = Convert.ToInt32(complaintId);
                List <Spam> spams = (from s
                                     in context.Spams
                                     where s.complaintId == cid
                                     orderby s.date descending
                                     select s).ToList();

                foreach (Spam spam in spams)
                {
                    spamItem temp = new spamItem();
                    temp.complaintId = spam.complaintId;
                    temp.userId      = spam.userId;
                    temp.date        = spam.date;
                    list.Add(temp);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("DEBUG", "GetSpam/{complaintId}", complaintId + "/ finished GetSpam/{complaintId}", null);
                return(list.ToArray());
            }
            catch (Exception ex)
            {
                error.ErrorMessage = "Something happened. Sorry.";
                error.ErrorDetails = ex.ToString();
                error.Result       = false;
                logger.LogMethod("ERROR", "GetSpam/{complaintId}", complaintId + ex.ToString(), null);
                throw new FaultException <Bug>(error, ex.Message.ToString());
            }
        }
Пример #11
0
        //GetComplaintsByStatus
        #region GetComplaintsByStatus/{complaintStatus}
        public complaintItem[] GetComplaintsByStatus(string complaintStatus)
        {
            try
            {
                logger.LogMethod("DEBUG", "GetComplaintsByStatus/{complaintStatus}", complaintStatus + "/ started GetComplaintsByStatus/{complaintStatus}", null);
                key = complaintStatus + "GetComplaintsByStatus";
                List <complaintItem> list = new List <complaintItem>();
                context = new SocialCopsEntities();

                //Checking if the complaints exist in cache
                //retrieveing complaints if they do.
                if (CachingConfig.CachingEnabled)
                {
                    list = (List <complaintItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("CACHE", "GetComplaintsByStatus/{complaintStatus}", complaintStatus + "/ Cache Found - GetComplaintsByStatus/{complaintStatus}", null);
                        return(list.ToArray());
                    }
                }
                list = new List <complaintItem>();
                List <Complaint> complaints = (from c
                                               in context.Complaints
                                               where c.complaintStatus == complaintStatus
                                               orderby c.complaintDate descending
                                               select c).ToList();

                foreach (Complaint temp in complaints)
                {
                    complaintItem complaint = new complaintItem();
                    complaint = complaintItem.convertComplaint(temp);
                    list.Add(complaint);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("DEBUG", "GetComplaintsByStatus/{complaintStatus}", complaintStatus + "/ finished GetComplaintsByStatus/{complaintStatus}", null);
                return(list.ToArray());
            }
            catch (Exception ex)
            {
                logger.LogMethod("ERROR", "GetComplaintsByStatus/{complaintStatus}", complaintStatus + "/ " + ex.Message);
                error.Result       = false;
                error.ErrorMessage = "unforeseen error occured. Please try later.";
                error.ErrorDetails = ex.ToString();
                throw new FaultException <Bug>(error, ex.ToString());
            }
        }
Пример #12
0
        //GetLikes/{complaintId}
        #region GetLikes/{complaintId}
        public likeItem[] GetLikes(String complaintId)
        {
            try
            {
                logger.LogMethod("DEBUG", "GetLikes/{complaintId}", complaintId + "/ started GetLikes/{complaintId}", null);
                List <likeItem> list = new List <likeItem>();
                key = complaintId + "GetLikes";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List <likeItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetLikes", "Cache found");
                        return(list.ToArray());
                    }
                }
                list    = new List <likeItem>();
                context = new SocialCopsEntities();
                int         cid   = Convert.ToInt32(complaintId);
                List <Like> likes = (from c
                                     in context.Likes
                                     where c.complaintId == cid
                                     orderby c.date descending
                                     select c).ToList();

                foreach (Like like in likes)
                {
                    likeItem temp = new likeItem();
                    temp.complaintId = like.complaintId;
                    temp.date        = like.date;
                    temp.userId      = like.userId;
                    list.Add(temp);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("DEBUG", "GetLikes/{complaintId}", complaintId + "/ finished GetLikes/{complaintId}", null);
                return(list.ToArray());
            }
            catch (Exception ex)
            {
                error.Result       = false;
                error.ErrorMessage = "Something happened. Sorry";
                logger.LogMethod("ERROR", "GetLikes/{complaintId}", complaintId + ex.ToString(), null);

                throw new FaultException <Bug>(error, ex.Message.ToString());
            }
        }
Пример #13
0
        public complaintItem[] GetComplaintsByPin(string pin)
        {
            try
            {
                logger.LogMethod("jo", "GetComplaintsByPin", "Enter");
                key = pin + "GetComplaintsByPin";
                List <complaintItem> list = new List <complaintItem>();
                context = new SocialCopsEntities();

                //Checking if the complaints exist in cache
                //retrieveing complaints if they do.
                if (CachingConfig.CachingEnabled)
                {
                    list = (List <complaintItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetComplaintsByPin", "Cache Found");
                        return(list.ToArray());
                    }
                }
                list = new List <complaintItem>();
                List <Complaint> complaints = (from c
                                               in context.Complaints
                                               where c.pincode == pin
                                               orderby c.complaintDate descending
                                               select c).ToList();

                foreach (Complaint temp in complaints)
                {
                    complaintItem complaint = new complaintItem();
                    complaint = complaintItem.convertComplaint(temp);
                    list.Add(complaint);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("jo", "GetComplaintsByPin", "Exit");
                return(list.ToArray());
            }
            catch (Exception ex)
            {
                error.Result       = false;
                error.ErrorMessage = "unforeseen error occured. Please try later.";
                error.ErrorDetails = ex.ToString();
                throw new FaultException <Bug>(error, ex.ToString());
            }
        }
Пример #14
0
 public bool SaveLike(likeItem like)
 {
     try
     {
         logger.LogMethod("DEBUG", "SaveLike/{complaintId}", like.complaintId + "/ started SaveLike/{complaintId}", null);
         context = new SocialCopsEntities();
         Like temp = new Like();
         temp.complaintId = like.complaintId;
         temp.userId      = like.userId;
         temp.date        = like.date;
         context.Likes.Add(temp);
         context.SaveChanges();
         logger.LogMethod("DEBUG", "SaveLike/{complaintId}", like.complaintId + "/ finished SaveLike/{complaintId}", null);
         return(true);
     }
     catch (Exception ex)
     {
         error.Result       = false;
         error.ErrorMessage = "Something happened. Sorry.";
         logger.LogMethod("ERROR", "SaveLike/{complaintId}", like.complaintId + ex.ToString(), null);
         throw new FaultException <Bug>(error, ex.Message.ToString());
     }
 }
Пример #15
0
        // Async CallBack when ImageUpload Finishes
        #region FinishImageUpload
        public void FinishImageUpload(IAsyncResult result)
        {
            SaveImageBytes del = (SaveImageBytes)result.AsyncState;

            string[] str = del.EndInvoke(result);
            if (str[0].Length > 0)
            {
                int id = int.Parse(str[1]);
                try
                {
                    context = new SocialCopsEntities();
                    //Entry Log
                    logger.LogMethod("DEBUG", "FinishImageUpload", "Complaintid/" + id.ToString() + "/ started FinishImageUpload", null);
                    //Find the Complaint
                    List <Complaint> complaints = (from c
                                                   in context.Complaints
                                                   where c.complaintId == id
                                                   select c).ToList();
                    if (complaints.Count > 0)
                    {
                        complaints[0].picture = str[0];
                        //Exit Log
                        logger.LogMethod("DEBUG", "FinishImageUpload", "Complaintid/" + id.ToString() + "/ finished FinishImageUpload", null);
                    }

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    logger.LogMethod("ERROR", "FinishImageUpload", "Complaintid/" + id.ToString() + "/ " + ex.ToString(), null);
                    error.Result       = false;
                    error.ErrorMessage = "unforeseen error occured. Please try later.";
                    error.ErrorDetails = ex.ToString();
                    throw new FaultException <Bug>(error, ex.ToString());
                }
            }
        }
Пример #16
0
        public void FinishImageUpload(IAsyncResult result)
        {
            SaveImageBytes del=(SaveImageBytes)result.AsyncState;
            string[] str = del.EndInvoke(result);
            if(str[0].Length>0)
            {
            int id= int.Parse(str[1]);
            try
            {
                context = new SocialCopsEntities();
                //Entry Log
                logger.LogMethod("DEBUG", "FinishImageUpload", "Complaintid/" + id.ToString() + "/ started FinishImageUpload", null);
                //Find the Complaint
                List<Complaint> complaints = (from c
                                              in context.Complaints
                                              where c.complaintId == id
                                              select c).ToList();
                if (complaints.Count > 0)
                {
                    complaints[0].picture = str[0];
                    //Exit Log
                    logger.LogMethod("DEBUG", "FinishImageUpload", "Complaintid/" + id.ToString() + "/ finished FinishImageUpload", null);
                }

                context.SaveChanges();
            }
            catch (Exception ex)
            {
                logger.LogMethod("ERROR", "FinishImageUpload","Complaintid/" +  id.ToString() + "/ " + ex.ToString(), null);
                error.Result = false;
                error.ErrorMessage = "unforeseen error occured. Please try later.";
                error.ErrorDetails = ex.ToString();
                throw new FaultException<Bug>(error, ex.ToString());
            }
            }
        }
Пример #17
0
 public bool SaveSpam(spamItem spam)
 {
     try
     {
         logger.LogMethod("DEBUG", "SaveSpam/{complaintId}", spam.complaintId + "/ started SaveSpam/{complaintId}", null);
         context = new SocialCopsEntities();
         Spam temp = new Spam();
         temp.date        = spam.date;
         temp.complaintId = spam.complaintId;
         temp.userId      = spam.userId;
         context.Spams.Add(temp);
         context.SaveChanges();
         logger.LogMethod("DEBUG", "SaveSpam/{complaintId}", spam.complaintId + "/ finished SaveSpam/{complaintId}", null);
         return(true);
     }
     catch (Exception ex)
     {
         error.Result       = false;
         error.ErrorMessage = "Something happened. Sorry.";
         error.ErrorDetails = ex.ToString();
         logger.LogMethod("ERROR", "SaveSpam/{complaintId}", spam.complaintId + ex.ToString(), null);
         throw new FaultException <Bug>(error, ex.Message.ToString());
     }
 }
Пример #18
0
 public bool SaveComment(commentItem comment)
 {
     try
     {
         logger.LogMethod("DEBUG", "SaveComment/{complaintId}", comment.complaintId + "/ started SaveComment/{complaintId}", null);
         context = new SocialCopsEntities();
         Comment temp = new Comment();
         temp.comment1    = comment.comment;
         temp.complaintId = comment.complaintId;
         temp.userId      = comment.userId;
         temp.date        = System.DateTime.Now;
         context.Comments.Add(temp);
         context.SaveChanges();
         logger.LogMethod("DEBUG", "SaveComment/{complaintId}", comment.complaintId + "/ finished SaveComment/{complaintId}", null);
         return(true);
     }
     catch (Exception ex)
     {
         error.ErrorMessage = "Something happened. Sorry.";
         error.Result       = false;
         logger.LogMethod("ERROR", "SaveComment/{complaintId}", comment.complaintId + ex.ToString(), null);
         throw new FaultException <Bug>(error, ex.Message.ToString());
     }
 }
Пример #19
0
        public spamItem[] GetSpam(string complaintId)
        {
            try
            {
                logger.LogMethod("DEBUG", "GetSpam/{complaintId}", complaintId + "/ started GetSpam/{complaintId}", null);

                List<spamItem> list = new List<spamItem>();
                key = complaintId + "GetSpam";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List<spamItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("CACHE", "GetSpam/{complaintId}", complaintId + "/ Cache Found - GetSpam/{complaintId}", null);
                        return list.ToArray();
                    }
                }
                list = new List<spamItem>();
                context = new SocialCopsEntities();
                //Retrieving records from the database
                int cid = Convert.ToInt32(complaintId);
                List<Spam> spams = (from s
                                    in context.Spams
                                    where s.complaintId == cid
                                    orderby s.date descending
                                    select s).ToList();

                foreach (Spam spam in spams)
                {
                    spamItem temp = new spamItem();
                    temp.complaintId = spam.complaintId;
                    temp.userId = spam.userId;
                    temp.date = spam.date;
                    list.Add(temp);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("DEBUG", "GetSpam/{complaintId}", complaintId + "/ finished GetSpam/{complaintId}", null);
                return list.ToArray();

            }
            catch (Exception ex)
            {
                error.ErrorMessage = "Something happened. Sorry.";
                error.ErrorDetails = ex.ToString();
                error.Result = false;
                logger.LogMethod("ERROR", "GetSpam/{complaintId}", complaintId + ex.ToString(), null);
                throw new FaultException<Bug>(error, ex.Message.ToString());
            }
        }
Пример #20
0
        public complaintItem[] GetComplaintsByAuthId(string authId)
        {
            try
            {
                logger.LogMethod("jo", "GetComplaintsByAuthId", "Enter");
                List <complaintItem> list = new List <complaintItem>();
                key = authId + "GetComplaintsByAuthId";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List <complaintItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetComplaintsbyAuthId", "Cache found");
                        return(list.ToArray());
                    }
                }
                list = new List <complaintItem>();
                int aid = Convert.ToInt32(authId);
                context = new SocialCopsEntities();
                //Getting the complaintIds from jurisdiction table where id is authId
                var complaintIds = (from c
                                    in context.Jurisdictions
                                    where c.authId == aid
                                    select c.complaintId);

                if (complaintIds == null)
                {
                    logger.LogMethod("jo", "GetComplaintsByAuthId", "No Complaints exist under the given authority");
                    return(null);
                }

                List <Complaint> complaints = (from c
                                               in context.Complaints
                                               where complaintIds.Contains(c.complaintId)
                                               orderby c.complaintDate descending
                                               select c).ToList();

                foreach (Complaint temp in complaints)
                {
                    complaintItem complaint = new complaintItem();
                    complaint.complaintId     = temp.complaintId;
                    complaint.userId          = temp.userId;
                    complaint.title           = temp.title;
                    complaint.details         = temp.details;
                    complaint.numLikes        = (int)temp.numLikes;
                    complaint.numComments     = (int)temp.numComments;
                    complaint.picture         = temp.picture;
                    complaint.complaintDate   = (DateTime)temp.complaintDate;
                    complaint.location        = temp.location;
                    complaint.latitude        = (float)temp.latitude;
                    complaint.longitude       = (float)temp.longitude;
                    complaint.category        = temp.category;
                    complaint.complaintStatus = temp.complaintStatus;
                    complaint.date            = temp.date;
                    complaint.isAnonymous     = temp.isAnonymous;
                    complaint.thumbImage1     = temp.thumbImage1;
                    complaint.thumbImage2     = temp.thumbImage2;
                    complaint.city            = temp.city;
                    complaint.country         = temp.country;
                    complaint.state           = temp.state;
                    complaint.pincode         = temp.pincode;

                    list.Add(complaint);
                }

                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("jo", "GetComplaintsByAuthId", "Exit");
                return(list.ToArray());
            }
            catch (Exception ex)
            {
                error.ErrorMessage = "An error occurred. Sorry!";
                error.Result       = true;
                logger.LogMethod("jo", "GetComplaintsByAuthId", ex.Message);
                throw new FaultException <Bug>(error, ex.Message);
            }
        }
Пример #21
0
        public authorityItem GetAuthByEmail(string email)
        {
            try
            {
                logger.LogMethod("jo", "GetAuthByEmail", "Enter");
                //List<authorityItem> list = new List<authorityItem>();
                authorityItem temp = new authorityItem();
                key = email + "GetAuthByEmail";
                if (CachingConfig.CachingEnabled)
                {
                    temp = (authorityItem)WCFCache.Current[key];
                    if (temp != null)
                    {
                        logger.LogMethod("jo", "GetAuthByEmail", "Cache found");
                        return(temp);
                    }
                }
                temp    = new authorityItem();
                context = new SocialCopsEntities();
                //int aid = Convert.ToInt32(id);
                List <Authority> auths = (from a
                                          in context.Authorities
                                          where a.email == email
                                          orderby a.date descending
                                          select a).ToList();

                if (auths.Count == 0)
                {
                    error.ErrorMessage = "The auth doesn't exist.";
                    error.ErrorDetails = "The auth doesn't exist.";
                    error.Result       = false;
                    logger.LogMethod("jo", "GetAuthByEmail", "The auth doesn't exist.");
                    throw new FaultException <Bug>(error);
                }

                foreach (Authority auth in auths)
                {
                    //authorityItem temp = new authorityItem();
                    temp.authId      = auth.authId;
                    temp.authName    = auth.authName;
                    temp.authAddress = auth.authAddress;
                    temp.email       = auth.email;
                    temp.phone       = Convert.ToInt32(auth.phone);
                    temp.numPending  = (int)auth.numPending;
                    temp.numResolved = (int)auth.numResolved;
                    temp.latitude    = temp.latitude;
                    temp.longitude   = temp.longitude;
                    temp.website     = auth.website;
                    temp.profilePic  = auth.profilePic;
                    temp.flag        = (int)auth.flag;
                    temp.date        = auth.date;
                    temp.city        = auth.city;
                    temp.state       = auth.state;
                    temp.country     = auth.country;
                    temp.pincode     = auth.pincode;
                    //list.Add(temp);
                }
                Cache.Cache.AddToCache(key, temp);
                logger.LogMethod("jo", "GetAuthByEmail", "Exit");
                return(temp);
            }
            catch (Exception ex)
            {
                error.ErrorDetails = ex.Message.ToString();
                error.ErrorMessage = "Something happened. Sorry.";
                error.Result       = false;
                logger.LogMethod("jo", "GetAuthByEmail", ex.Message.ToString());
                throw new FaultException <Bug>(error, ex.Message.ToString());
            }
        }
Пример #22
0
        public int SaveMuteAuth(muteAuthorityItem muteAuth)
        {
            try
            {
                logger.LogMethod("jo", "SaveMuteAuth", "Enter", null);
                context = new SocialCopsEntities();
                MuteAuthority temp = new MuteAuthority();

                List<MuteAuthority> muteAuths = (from m
                                    in context.MuteAuthorities
                                    where m.email == muteAuth.email
                                    select m).ToList();

                if (muteAuths.Count > 0)
                {
                    logger.LogMethod("jo", "SaveMuteAuth", "Invalid Sign-up. Email address already exists.");
                    error.ErrorDetails = "Email address already exists.";
                    error.Result = false;
                    error.ErrorMessage = "Email address already exists. Cannot register again.";
                    throw new WebFaultException<Bug>(error, System.Net.HttpStatusCode.NotAcceptable);
                }

                temp.muteAuthName = muteAuth.muteAuthName;
                temp.muteAuthAddress = muteAuth.muteAuthAddress;
                temp.city = muteAuth.city;
                temp.state = muteAuth.state;
                temp.country = muteAuth.country;
                temp.email = muteAuth.email;
                temp.phone = muteAuth.phone;
                temp.latitude = muteAuth.latitude;
                temp.longitude = muteAuth.longitude;
                temp.website = muteAuth.website;
                temp.pic = muteAuth.pic;
                temp.date = System.DateTime.Now;
                temp.flag = muteAuth.flag;
                temp.pincode = muteAuth.pincode;

                context.MuteAuthorities.Add(temp);
                context.SaveChanges();
                logger.LogMethod("jo", "SaveMuteAuth", "Exit", null);
                //userItem u = (userItem)context.Entry(temp);
                return temp.muteAuthId;
            }
            catch (WebFaultException<Bug> ex)
            {

                throw;
            }
            catch (Exception ex)
            {
                error.Result = false;
                error.ErrorMessage = "unforeseen error occured. Please try later.";
                error.ErrorDetails = ex.ToString();
                throw new FaultException<Bug>(error, ex.ToString());
            }
        }
Пример #23
0
        public authorityItem[] GetAuthsByState(string state)
        {
            try
            {
                logger.LogMethod("jo", "GetAuthsByState", "Enter");
                List<authorityItem> list = new List<authorityItem>();
                key = state + "GetAuthsByState";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List<authorityItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetAuthsByState", "Cache found");
                        return list.ToArray();
                    }
                }
                list = new List<authorityItem>();
                context = new SocialCopsEntities();
                List<Authority> auths = (from a
                                         in context.Authorities
                                         where a.state == state
                                         orderby a.date descending
                                         select a).ToList();

                foreach (Authority auth in auths)
                {
                    authorityItem temp = new authorityItem();
                    temp.authId = auth.authId;
                    temp.authName = auth.authName;
                    temp.authAddress = auth.authAddress;
                    temp.email = auth.email;
                    temp.phone = Convert.ToInt32(auth.phone);
                    temp.numPending = (int)auth.numPending;
                    temp.numResolved = (int)auth.numResolved;
                    temp.latitude = temp.latitude;
                    temp.longitude = temp.longitude;
                    temp.website = auth.website;
                    temp.profilePic = auth.profilePic;
                    temp.flag = (int)auth.flag;
                    temp.date = auth.date;
                    temp.city = auth.city;
                    temp.state = auth.state;
                    temp.country = auth.country;
                    temp.pincode = auth.pincode;
                    list.Add(temp);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("jo", "GetAuthsByState", "Exit");
                return list.ToArray();

            }
            catch (Exception ex)
            {
                error.ErrorDetails = ex.Message.ToString();
                error.ErrorMessage = "Something happened. Sorry.";
                error.Result = false;
                logger.LogMethod("jo", "GetAuthsByState", ex.Message.ToString());
                throw new FaultException<Bug>(error, ex.Message.ToString());
            }
        }
Пример #24
0
        public authorityItem GetAuthById(string id)
        {
            try
            {
                logger.LogMethod("jo", "GetAuthById", "Enter");
                //List<authorityItem> list = new List<authorityItem>();
                authorityItem temp = new authorityItem();
                key = id + "GetAuthById";
                if (CachingConfig.CachingEnabled)
                {
                    temp = (authorityItem)WCFCache.Current[key];
                    if (temp != null)
                    {
                        logger.LogMethod("jo", "GetAuthById", "Cache found");
                        return temp;
                    }
                }
                temp = new authorityItem();
                context = new SocialCopsEntities();
                int aid = Convert.ToInt32(id);
                List<Authority> auths = (from a
                                         in context.Authorities
                                         where a.authId == aid
                                         orderby a.date descending
                                         select a).ToList();

                if (auths.Count == 0)
                {
                    error.ErrorMessage = "The auth doesn't exist.";
                    error.ErrorDetails = "The auth doesn't exist.";
                    error.Result = false;
                    logger.LogMethod("jo", "GetAuthById", "The auth doesn't exist.");
                    throw new FaultException<Bug>(error);
                }

                foreach (Authority auth in auths)
                {
                    //authorityItem temp = new authorityItem();
                    temp.authId = auth.authId;
                    temp.authName = auth.authName;
                    temp.authAddress = auth.authAddress;
                    temp.email = auth.email;
                    temp.phone = Convert.ToInt32(auth.phone);
                    temp.numPending = (int)auth.numPending;
                    temp.numResolved = (int)auth.numResolved;
                    temp.latitude = temp.latitude;
                    temp.longitude = temp.longitude;
                    temp.website = auth.website;
                    temp.profilePic = auth.profilePic;
                    temp.flag = (int)auth.flag;
                    temp.date = auth.date;
                    temp.city = auth.city;
                    temp.state = auth.state;
                    temp.country = auth.country;
                    temp.pincode = auth.pincode;
                    //list.Add(temp);
                }
                Cache.Cache.AddToCache(key, temp);
                logger.LogMethod("jo", "GetAuthById", "Exit");
                return temp;

            }
            catch (Exception ex)
            {
                error.ErrorDetails = ex.Message.ToString();
                error.ErrorMessage = "Something happened. Sorry.";
                error.Result = false;
                logger.LogMethod("jo", "GetAuthById", ex.Message.ToString());
                throw new FaultException<Bug>(error, ex.Message.ToString());
            }
        }
Пример #25
0
        public complaintItem[] GetComplaintsByAuthId(string authId)
        {
            try
            {
                logger.LogMethod("jo", "GetComplaintsByAuthId", "Enter");
                List<complaintItem> list = new List<complaintItem>();
                key = authId + "GetComplaintsByAuthId";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List<complaintItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetComplaintsbyAuthId", "Cache found");
                        return list.ToArray();
                    }
                }
                list = new List<complaintItem>();
                int aid = Convert.ToInt32(authId);
                context = new SocialCopsEntities();
                //Getting the complaintIds from jurisdiction table where id is authId
                var complaintIds = (from c
                                                   in context.Jurisdictions
                                    where c.authId == aid
                                    select c.complaintId);

                if (complaintIds == null)
                {
                    logger.LogMethod("jo", "GetComplaintsByAuthId", "No Complaints exist under the given authority");
                    return null;
                }

                List<Complaint> complaints = (from c
                                              in context.Complaints
                                              where complaintIds.Contains(c.complaintId)
                                              orderby c.complaintDate descending
                                              select c).ToList();

                foreach (Complaint temp in complaints)
                {
                    complaintItem complaint = new complaintItem();
                    complaint.complaintId = temp.complaintId;
                    complaint.userId = temp.userId;
                    complaint.title = temp.title;
                    complaint.details = temp.details;
                    complaint.numLikes = (int)temp.numLikes;
                    complaint.numComments = (int)temp.numComments;
                    complaint.picture = temp.picture;
                    complaint.complaintDate = (DateTime)temp.complaintDate;
                    complaint.location = temp.location;
                    complaint.latitude = (float)temp.latitude;
                    complaint.longitude = (float)temp.longitude;
                    complaint.category = temp.category;
                    complaint.complaintStatus = temp.complaintStatus;
                    complaint.date = temp.date;
                    complaint.isAnonymous = temp.isAnonymous;
                    complaint.thumbImage1 = temp.thumbImage1;
                    complaint.thumbImage2 = temp.thumbImage2;
                    complaint.city = temp.city;
                    complaint.country = temp.country;
                    complaint.state = temp.state;
                    complaint.pincode = temp.pincode;

                    list.Add(complaint);
                }

                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("jo", "GetComplaintsByAuthId", "Exit");
                return list.ToArray();
            }
            catch (Exception ex)
            {
                error.ErrorMessage = "An error occurred. Sorry!";
                error.Result = true;
                logger.LogMethod("jo", "GetComplaintsByAuthId", ex.Message);
                throw new FaultException<Bug>(error, ex.Message);
            }
        }
Пример #26
0
        public complaintItem[] GetComplaintsByPin(string pin)
        {
            try
            {
                logger.LogMethod("jo", "GetComplaintsByPin", "Enter");
                key = pin + "GetComplaintsByPin";
                List<complaintItem> list = new List<complaintItem>();
                context = new SocialCopsEntities();

                //Checking if the complaints exist in cache
                //retrieveing complaints if they do.
                if (CachingConfig.CachingEnabled)
                {
                    list = (List<complaintItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("jo", "GetComplaintsByPin", "Cache Found");
                        return list.ToArray();
                    }
                }
                list = new List<complaintItem>();
                List<Complaint> complaints = (from c
                                              in context.Complaints
                                              where c.pincode == pin
                                              orderby c.complaintDate descending
                                              select c).ToList();

                foreach (Complaint temp in complaints)
                {
                    complaintItem complaint = new complaintItem();
                   complaint= complaintItem.convertComplaint(temp);
                    list.Add(complaint);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("jo", "GetComplaintsByPin", "Exit");
                return list.ToArray();

            }
            catch (Exception ex)
            {
                error.Result = false;
                error.ErrorMessage = "unforeseen error occured. Please try later.";
                error.ErrorDetails = ex.ToString();
                throw new FaultException<Bug>(error, ex.ToString());
            }
        }
Пример #27
0
        public complaintItem GetComplaintsById(string id)
        {
            complaintItem temp = new complaintItem();
            key = id + "GetComplaints";
            try
            {
                logger.LogMethod("DEBUG", "GetComplaints/{id}", id+ "/ started GetComplaints/{id}", null);
                context = new SocialCopsEntities();
                if (CachingConfig.CachingEnabled)
                {
                    temp = (complaintItem)WCFCache.Current[key];
                    if (temp != null)
                    {
                        logger.LogMethod("CACHE", "GetComplaints/{id}", id + "/ Cache Found - finished GetComplaints/{id}", null);
                        return temp;
                    }
                }
                int cId = Convert.ToInt32(id);
                List<Complaint> complaints = (from c
                                              in context.Complaints
                                              where c.complaintId == cId
                                              select c).ToList();
                temp = new complaintItem();
                if (complaints.Count == 0)
                {
                    error.Result = false;
                    error.ErrorMessage = "Invalid request. There is no complaint of the given id.";
                    logger.LogMethod("ERROR", "GetComplaints/{id}", id+  "/ Invalid request. There is no complaint of the given id.", null);
                    throw new FaultException<Bug>(error);
                }

                foreach (Complaint complaint in complaints)
                {
                    temp = complaintItem.convertComplaint(complaint);
                }
                Cache.Cache.AddToCache(key, temp);
                logger.LogMethod("DEBUG", "GetComplaints/{id}", id + "/ finished GetComplaints/{id}", null);
                return temp;
            }
            catch (Exception ex)
            {
                error.Result = false;
                error.ErrorMessage = "unforeseen error occured. Please try again later";
                logger.LogMethod("ERROR", "GetComplaints/{id}", id+ "/ "+ ex.Message);
                throw new FaultException<Bug>(error, ex.ToString());
            }
        }
Пример #28
0
        public commentItem[] GetComments(String complaintId)
        {
            try
            {
                logger.LogMethod("DEBUG", "GetComments/{complaintId}", complaintId + "/ started GetComments/{complaintId}", null);
                List<commentItem> list = new List<commentItem>();
                key = complaintId + "GetComments";
                if (CachingConfig.CachingEnabled)
                {
                    list = (List<commentItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("CACHE", "GetComments/{complaintId}", complaintId + "/ Cache Found - finished GetComments/{complaintId}", null);
                        return list.ToArray();
                    }
                }
                list = new List<commentItem>();
                context = new SocialCopsEntities();
                int cid = Convert.ToInt32(complaintId);
                List<Comment> comments = (from c
                                          in context.Comments
                                          where c.complaintId == cid
                                          orderby c.date descending
                                          select c).ToList();

                foreach (Comment comment in comments)
                {
                    commentItem temp = new commentItem();
                    temp.comment = comment.comment1;
                    temp.complaintId = comment.complaintId;
                    temp.userId = comment.userId;
                    temp.date = comment.date;
                    list.Add(temp);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("DEBUG", "GetComments/{complaintId}", complaintId + "/ finished GetComments/{complaintId}", null);
                return list.ToArray();
            }
            catch (Exception ex)
            {
                error.Result = false;
                error.ErrorMessage = "Something happened. Sorry";
                logger.LogMethod("ERROR", "GetComments/{complaintId}", complaintId + ex.ToString(), null);
                throw new FaultException<Bug>(error, ex.Message.ToString());
            }
        }
Пример #29
0
 public bool SaveSpam(spamItem spam)
 {
     try
     {
         logger.LogMethod("DEBUG", "SaveSpam/{complaintId}", spam.complaintId + "/ started SaveSpam/{complaintId}", null);
         context = new SocialCopsEntities();
         Spam temp = new Spam();
         temp.date = spam.date;
         temp.complaintId = spam.complaintId;
         temp.userId = spam.userId;
         context.Spams.Add(temp);
         context.SaveChanges();
         logger.LogMethod("DEBUG", "SaveSpam/{complaintId}", spam.complaintId + "/ finished SaveSpam/{complaintId}", null);
         return true;
     }
     catch (Exception ex)
     {
         error.Result = false;
         error.ErrorMessage = "Something happened. Sorry.";
         error.ErrorDetails = ex.ToString();
         logger.LogMethod("ERROR", "SaveSpam/{complaintId}", spam.complaintId + ex.ToString(), null);
         throw new FaultException<Bug>(error, ex.Message.ToString());
     }
 }
Пример #30
0
 public bool SaveLike(likeItem like)
 {
     try
     {
         logger.LogMethod("DEBUG", "SaveLike/{complaintId}", like.complaintId + "/ started SaveLike/{complaintId}", null);
         context = new SocialCopsEntities();
         Like temp = new Like();
         temp.complaintId = like.complaintId;
         temp.userId = like.userId;
         temp.date = like.date;
         context.Likes.Add(temp);
         context.SaveChanges();
         logger.LogMethod("DEBUG", "SaveLike/{complaintId}", like.complaintId + "/ finished SaveLike/{complaintId}", null);
         return true;
     }
     catch (Exception ex)
     {
         error.Result = false;
         error.ErrorMessage = "Something happened. Sorry.";
         logger.LogMethod("ERROR", "SaveLike/{complaintId}", like.complaintId + ex.ToString(), null);
         throw new FaultException<Bug>(error, ex.Message.ToString());
     }
 }
Пример #31
0
        public complaintItem[] GetComplaintsByStatus(string complaintStatus)
        {
            try
            {
                logger.LogMethod("DEBUG", "GetComplaintsByStatus/{complaintStatus}", complaintStatus + "/ started GetComplaintsByStatus/{complaintStatus}", null);
                key = complaintStatus + "GetComplaintsByStatus";
                List<complaintItem> list = new List<complaintItem>();
                context = new SocialCopsEntities();

                //Checking if the complaints exist in cache
                //retrieveing complaints if they do.
                if (CachingConfig.CachingEnabled)
                {
                    list = (List<complaintItem>)WCFCache.Current[key];
                    if (list != null)
                    {
                        logger.LogMethod("CACHE", "GetComplaintsByStatus/{complaintStatus}", complaintStatus + "/ Cache Found - GetComplaintsByStatus/{complaintStatus}", null);
                        return list.ToArray();
                    }
                }
                list = new List<complaintItem>();
                List<Complaint> complaints = (from c
                                              in context.Complaints
                                              where c.complaintStatus == complaintStatus
                                              orderby c.complaintDate descending
                                              select c).ToList();

                foreach (Complaint temp in complaints)
                {
                    complaintItem complaint = new complaintItem();
                    complaint=complaintItem.convertComplaint(temp);
                    list.Add(complaint);
                }
                Cache.Cache.AddToCache(key, list);
                logger.LogMethod("DEBUG", "GetComplaintsByStatus/{complaintStatus}", complaintStatus + "/ finished GetComplaintsByStatus/{complaintStatus}", null);
                return list.ToArray();

            }
            catch (Exception ex)
            {
                logger.LogMethod("ERROR", "GetComplaintsByStatus/{complaintStatus}", complaintStatus + "/ " + ex.Message);
                error.Result = false;
                error.ErrorMessage = "unforeseen error occured. Please try later.";
                error.ErrorDetails = ex.ToString();
                throw new FaultException<Bug>(error, ex.ToString());
            }
        }
Пример #32
0
        public bool SaveComment(commentItem comment)
        {
            try
            {
                logger.LogMethod("DEBUG", "SaveComment/{complaintId}", comment.complaintId + "/ started SaveComment/{complaintId}", null);
                context = new SocialCopsEntities();
                Comment temp = new Comment();
                temp.comment1 = comment.comment;
                temp.complaintId = comment.complaintId;
                temp.userId = comment.userId;
                temp.date = System.DateTime.Now;
                context.Comments.Add(temp);
                context.SaveChanges();
                logger.LogMethod("DEBUG", "SaveComment/{complaintId}", comment.complaintId + "/ finished SaveComment/{complaintId}", null);
                return true;

            }
            catch (Exception ex)
            {
                error.ErrorMessage = "Something happened. Sorry.";
                error.Result = false;
                logger.LogMethod("ERROR", "SaveComment/{complaintId}", comment.complaintId +ex.ToString(), null);
                throw new FaultException<Bug>(error, ex.Message.ToString());
            }
        }