public ActionResult NewClaim(TenderClaim model, string managerSid)
 {
     var manager = new EmployeeSm(managerSid);
     model.Manager = new Manager()
     {
         Id = manager.AdSid,
         ShortName = manager.DisplayName,
         SubDivision = manager.DepartmentName
     };
     model.Author = GetUser();
     model.RecordDate = DateTime.Now;
     model.ClaimStatus = 1;
     model.TenderStatus = 1;
     var db = new DbEngine();
     var success = db.SaveTenderClaim(ref model);
     if (success)
     {
         string message = "";
         if (Request.Files.Count > 0)
         {
             int idClaim = model.Id;
             if (idClaim != null && idClaim > 0)
             {
                 for (int i = 0; i < Request.Files.Count; i++)
                 {
                     var file = Request.Files[i];
                     var fileFormats = WebConfigurationManager.AppSettings["FileFormat4TenderClaimFile"].Split(',').Select(s => s.ToLower()).ToArray();
                     byte[] fileData = null;
                     if (Array.IndexOf(fileFormats, Path.GetExtension(file.FileName).ToLower()) > -1)
                     {
                         using (var br = new BinaryReader(file.InputStream))
                         {
                             fileData = br.ReadBytes(file.ContentLength);
                         }
                         var claimFile = new TenderClaimFile() { IdClaim = idClaim, File = fileData, FileName = file.FileName };
                         db.SaveTenderClaimFile(ref claimFile);
                     }
                     else if (file.ContentLength > 0) message += String.Format("Файл {0} имеет недопустимое расширение.", file.FileName);
                 }
                 //}
             }
         }
         TempData["error"] = message;
         if (success)
         {
             //История изменения статуса
             var statusHistory = new ClaimStatusHistory()
             {
                 Date = DateTime.Now,
                 IdClaim = model.Id,
                 IdUser = model.Author.Id,
                 Status = new ClaimStatus() { Id = model.ClaimStatus },
                 Comment = "Автор: " + model.Author.ShortName
             };
             db.SaveClaimStatusHistory(statusHistory);
             statusHistory.DateString = statusHistory.Date.ToString("dd.MM.yyyy HH:mm");
             //>>>>Уведомления
             if (model.Author.Id != model.Manager.Id)
             {
                 var host = ConfigurationManager.AppSettings["AppHost"];
                 var emessage = new StringBuilder();
                 emessage.Append("Добрый день!");
                 //message.Append(manager.Name);
                 emessage.Append("<br/>");
                 emessage.Append("Пользователь ");
                 emessage.Append(model.Author.ShortName);
                 emessage.Append(" создал заявку где Вы назначены менеджером.");
                 emessage.Append("<br/><br />");
                 emessage.Append(GetClaimInfo(model));
                 emessage.Append("<br/>");
                 emessage.Append("Ссылка на заявку: ");
                 emessage.Append("<a href='" + host + "/Claim/Index?claimId=" + model.Id + "'>" + host +
                                "/Claim/Index?claimId=" + model.Id + "</a>");
                 //message.Append("<br/>Сообщение от системы Спец расчет");
                 Notification.SendNotification(new List<UserBase>() { manager.GetUserBase(new List<Role>() { Role.Manager }) }, emessage.ToString(),
                     String.Format("{0} - {1} - Новая заявка СпецРасчет", model.TenderNumber, model.Customer));
             }
         }
         return RedirectToAction("Index", "Claim", new { claimId = model.Id });
     }
     return RedirectToAction("NewClaim", "Claim", new { errorMessage = "при сохранении возникла ошибка" });
 }
        public ActionResult SaveFile(string formClaimId)
        {
            string message = "";
            if (Request.Files.Count > 0)
            {
                int? idClaim = null;
                try
                {
                    idClaim = Convert.ToInt32(formClaimId);
                    //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];
                        var fileFormats = WebConfigurationManager.AppSettings["FileFormat4TenderClaimFile"].Split(',').Select(s => s.ToLower()).ToArray();
                        byte[] fileData = null;
                        if (Array.IndexOf(fileFormats, Path.GetExtension(file.FileName).ToLower()) > -1)
                        {
                          using (var br = new BinaryReader(file.InputStream))
                        {
                            fileData = br.ReadBytes(file.ContentLength);
                        }
                        var db = new DbEngine();
                        var claimFile = new TenderClaimFile() { IdClaim = idClaim.Value, File = fileData, FileName = file.FileName };
                        db.SaveTenderClaimFile(ref claimFile);
                        }
                       else if (file.ContentLength > 0) message += String.Format("Файл {0} имеет недопустимое расширение.",file.FileName);
                    }
                    //}
                }
            }
            TempData["error"] = message;
            return RedirectToAction("Index", "Claim", new { claimId = formClaimId});
        }
Ejemplo n.º 3
0
        public bool SaveTenderClaimFile(ref TenderClaimFile model)
        {
            var result = false;
            using (var conn = new SqlConnection(_connectionString))
            {
                var cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SaveTenderClaimFile";
                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;
        }