public JsonResult SaveClaim(TenderClaim model) { var isComplete = false; ClaimStatusHistory statusHistory = null; int? idClaim; string errorText = String.Empty; try { model.KPDeadline = DateTime.ParseExact(model.KPDeadlineString, "dd.MM.yyyy", CultureInfo.CurrentCulture); model.ClaimDeadline = DateTime.ParseExact(model.ClaimDeadlineString, "dd.MM.yyyy", CultureInfo.CurrentCulture); model.TenderStart = DateTime.ParseExact(model.TenderStartString, "dd.MM.yyyy", CultureInfo.CurrentCulture); if (!string.IsNullOrEmpty(model.DeliveryDateString)) model.DeliveryDate = DateTime.ParseExact(model.DeliveryDateString, "dd.MM.yyyy", CultureInfo.CurrentCulture); if (!string.IsNullOrEmpty(model.DeliveryDateEndString)) model.DeliveryDateEnd = DateTime.ParseExact(model.DeliveryDateEndString, "dd.MM.yyyy", CultureInfo.CurrentCulture); if (!string.IsNullOrEmpty(model.AuctionDateString)) model.AuctionDate = DateTime.ParseExact(model.AuctionDateString, "dd.MM.yyyy", CultureInfo.CurrentCulture); var modelValid = true; if (string.IsNullOrEmpty(model.Customer) || model.Sum < 0) modelValid = false; if (modelValid) { var user = GetUser(); var db = new DbEngine(); model.ClaimStatus = 1; model.TenderStatus = 1; model.Deleted = false; model.RecordDate = DateTime.Now; model.Author = UserHelper.GetUserById(user.Id); isComplete = db.SaveTenderClaim(ref model); if (model.DeliveryDateString == null) model.DeliveryDateString = string.Empty; if (model.DeliveryDateEndString == null) model.DeliveryDateEndString = string.Empty; if (model.AuctionDateString == null) model.AuctionDateString = string.Empty; if (model.DeliveryPlace == null) model.DeliveryPlace = string.Empty; if (isComplete) { //История изменения статуса statusHistory = new ClaimStatusHistory() { Date = DateTime.Now, IdClaim = model.Id, IdUser = user.Id, Status = new ClaimStatus() { Id = model.ClaimStatus }, Comment = "Автор: " + user.ShortName }; db.SaveClaimStatusHistory(statusHistory); statusHistory.DateString = statusHistory.Date.ToString("dd.MM.yyyy HH:mm"); //>>>>Уведомления if (model.Author.Id != model.Manager.Id) { var manager = UserHelper.GetUserById(model.Manager.Id); if (manager != null) { var host = ConfigurationManager.AppSettings["AppHost"]; var message = new StringBuilder(); message.Append("Добрый день!"); //message.Append(manager.Name); message.Append("<br/>"); message.Append("Пользователь "); message.Append(user.ShortName); message.Append(" создал заявку где Вы назначены менеджером."); message.Append("<br/><br />"); message.Append(GetClaimInfo(model)); message.Append("<br/>"); message.Append("Ссылка на заявку: "); message.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 }, message.ToString(), String.Format("{0} - {1} - Новая заявка СпецРасчет", model.TenderNumber, model.Customer)); } } } } } catch (Exception ex) { isComplete = false; errorText = ex.Message; } return Json(new { IsComplete = isComplete, Model = model, StatusHistory = statusHistory, errorText = errorText }); }
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 = "при сохранении возникла ошибка" }); }