Пример #1
0
        public bool SaveClaimCertFile(ref ClaimCert model)
        {
            var result = false;
            using (var conn = new SqlConnection(_connectionString))
            {
                var cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SaveClaimCertFile";
                cmd.Parameters.AddWithValue("@IdClaim", model.IdClaim);
                cmd.Parameters.AddWithValue("@file", model.File);
                cmd.Parameters.AddWithValue("@fileName", model.FileName);
                conn.Open();
                var rd = cmd.ExecuteReader();
                if (rd.HasRows)
                {
                    rd.Read();
                    var id = rd.GetInt32(0);
                    if (id != -1)
                    {
                        result = true;
                        model.Id = id;
                    }
                }
                rd.Dispose();
            }

            return result;
        }
        public ActionResult SaveFile(string claimId)
        {
            if (Request.Files.Count > 0)
            {
                int? idClaim = null;

                try
                {
                    idClaim = Convert.ToInt32(Request.QueryString["claimId"]);
                    //idClaim = Convert.ToInt32(RouteData.Values["claimId"]);

                }
                catch (Exception ex)
                {
                    idClaim = null;
                }

                if (idClaim != null && idClaim > 0)
                {
                    //foreach (HttpPostedFileWrapper file in Request.Files)
                    //{
                    for(int i=0; i<Request.Files.Count; i++)
                    {
                        var file = Request.Files[i];
                        byte[] fileData = null;
                        using (var br = new BinaryReader(file.InputStream))
                        {
                            fileData = br.ReadBytes(file.ContentLength);
                        }
                        var db = new DbEngine();
                        var cert = new ClaimCert() {IdClaim = idClaim.Value, File = fileData, FileName = file.FileName};
                        db.SaveClaimCertFile(ref cert);
                    }
                    //}
                }
            }

            return RedirectToAction("Index", "Calc", new { claimId = Request.QueryString["claimId"] });
        }