Exemplo n.º 1
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());
     }
 }
Exemplo n.º 2
0
        public int SaveComplaint(complaintItem complaint)
        {
            cc = new ComplaintController();
            int result = cc.SaveComplaint(complaint);

            return(result);
        }
Exemplo n.º 3
0
        public complaintItem GetComplaintsById(string id)
        {
            cc = new ComplaintController();
            complaintItem result = cc.GetComplaintsById(id);

            return(result);
        }
Exemplo n.º 4
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());
            }
        }
Exemplo n.º 5
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());
            }
        }
Exemplo n.º 6
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());
            }
        }
Exemplo n.º 7
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);
            }
        }