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
 // 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());
     }
 }
示例#3
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());
                }
            }
        }