Example #1
0
 public DataSet INSERT_UPDATE_StudentTravelPlanVisa(mTravelPlanVisa _obj)
 {
     try
     {
         _cn.Open();
         SqlCommand _cmd = new SqlCommand("INSERT_UPDATE_StudentTravelPlanVisa", _cn);
         _cmd.Parameters.AddWithValue("@StudentID", _obj.StudentID);
         _cmd.Parameters.AddWithValue("@ApplicationNo", _obj.ApplicationNo);
         _cmd.Parameters.AddWithValue("@HaveIndianStudentVisa", _obj.HaveIndianStudentVisa);
         _cmd.Parameters.AddWithValue("@VisaNumber", _obj.VisaNumber);
         if (_obj.ExpiryDate != null)
         {
             if (_obj.ExpiryDate.Equals(""))
             {
                 _cmd.Parameters.AddWithValue("@ExpiryDate", DBNull.Value);
             }
             else
             {
                 _cmd.Parameters.AddWithValue("@ExpiryDate", DateTime.ParseExact(_obj.ExpiryDate.ToString(), "dd-MM-yyyy", null));
             }
         }
         else
         {
             _cmd.Parameters.AddWithValue("@ExpiryDate", DBNull.Value);
         }
         _cmd.Parameters.AddWithValue("@VisaType", _obj.VisaType);
         _cmd.Parameters.AddWithValue("@VisaDocument", _obj.VisaDocument);
         _cmd.Parameters.AddWithValue("@VisaApplicationNumber", _obj.VisaApplicationNumber);
         _cmd.Parameters.AddWithValue("@VisaApplicationDocument", _obj.VisaApplicationDocument);
         _cmd.Parameters.AddWithValue("@CreatedIP", _obj.CreatedIP);
         _cmd.CommandType = CommandType.StoredProcedure;
         SqlDataAdapter _adp = new SqlDataAdapter(_cmd);
         DataSet        _ds  = new DataSet();
         _adp.Fill(_ds);
         _adp.Dispose();
         _cmd.Dispose();
         return(_ds);
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         _cn.Close();
     }
 }
        public JsonResult SaveVisa(mTravelPlanVisa _obj)
        {
            string path = "";
            string folderPath = "";
            string Message = string.Empty, Code = string.Empty, Error = string.Empty;

            try
            {
                string filename = "";
                string fname    = "";
                if (Request.Files.Count > 0)
                {
                    if (Request.Files[0].ContentLength > 0)
                    {
                        HttpFileCollectionBase files = Request.Files;
                        folderPath = "Uploads/studentDocument/TravelPlan/" + Session["studentid"].ToString() + "/";
                        path       = AppDomain.CurrentDomain.BaseDirectory + folderPath;
                        filename   = Path.GetFileName(Request.Files[0].FileName);
                        HttpPostedFileBase file = files[0];
                        filename = Session["ApplicationNo"].ToString() + "_Visa_" + DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetExtension(file.FileName);
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        else
                        {
                            string[] curentfiles = Directory.GetFiles(path);
                            foreach (string curentfile in curentfiles)
                            {
                                if (curentfile.IndexOf(filename) >= 0)
                                {
#pragma warning disable SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                                    System.IO.File.Delete(path: curentfile);
#pragma warning restore SCS0018 // Path traversal: injection possible in {1} argument passed to '{0}'
                                }
                            }
                        }

                        fname = Path.Combine(Server.MapPath("~/" + folderPath), filename);
                        file.SaveAs(fname);
                        if (_obj.HaveIndianStudentVisa == "Yes, I have received the visa")
                        {
                            _obj.VisaDocument = folderPath + filename;
                        }
                        else if (_obj.HaveIndianStudentVisa == "I have applied for the visa. It is in-process")
                        {
                            _obj.VisaApplicationDocument = folderPath + filename;
                        }
                    }
                }
                _obj.CreatedIP     = Session["localIP"].ToString();
                _obj.StudentID     = Session["StudentID"].ToString();
                _obj.ApplicationNo = Session["ApplicationNo"].ToString();
                TravelPlanRepository _objRepository = new TravelPlanRepository();
                DataSet _ds = _objRepository.INSERT_UPDATE_StudentTravelPlanVisa(_obj);
                if (_ds != null)
                {
                    if (_ds.Tables[0].Rows.Count > 0)
                    {
                        Message = "Details saved successfully!";
                        Code    = "success";
                        Session["HasVisaDetails"] = "True";
                    }
                    else
                    {
                        Message = "Error from server side. Kindly refresh the page and try again.";
                        Code    = "servererror";
                    }
                }
                else
                {
                    Message = "Error from server side. Kindly refresh the page and try again.";
                    Code    = "servererror";
                }
            }
            catch (NullReferenceException ex)
            {
                Message = "Your session has been expired. Kindly login again.";
                Code    = "sessionexpired";
                Error   = ex.Message;
            }
            catch (Exception ex)
            {
                Message = "Error from server side. Kindly refresh the page and try again.";
                Code    = "servererror";
                Error   = ex.Message;
            }
            return(Json(new
            {
                m = Message,
                c = Code,
                e = Error
            },
                        JsonRequestBehavior.AllowGet
                        ));
        }