public ActionResult Create(EventApplicationViewModel @event) { EventApplication newEvent = new EventApplication() { From = new DateTime(@event.FromDate.Year, @event.FromDate.Month, @event.FromDate.Day, @event.FromTime.Hours, @event.FromTime.Minutes, 0, DateTimeKind.Local), Till = new DateTime(@event.TillDate.Year, @event.TillDate.Month, @event.TillDate.Day, @event.TillTime.Hours, @event.TillTime.Minutes, 0, DateTimeKind.Local), CreatorEmail = @event.CreatorEmail, CreatorName = @event.CreatorName, CreatorPhone = @event.CreatorPhone, Name = @event.Name, Description = @event.Description, Attachments = @event.Attachment }; if (newEvent.From < DateTime.Now) { ModelState.AddModelError(string.Empty, "Дата початку події має бути такою, яка ще не наступила."); } if (newEvent.From >= newEvent.Till) { ModelState.AddModelError(string.Empty, "Дата та час початку події мають бути раніше, ніж дата та час кінця події."); } foreach (Event e in db.Events) { if (GetIntersection(newEvent.From, newEvent.Till, e.From, e.Till) != TimeSpan.Zero) { ModelState.AddModelError(string.Empty, "В обраний проміжок часу вже заплановано подію."); return View(@event); } } if (ModelState.IsValid) { db.EventApplications.Add(newEvent); db.SaveChanges(); return RedirectToAction("Index", "Events"); } return View(@event); }
// returns a path to pdf application for this event private string GeneratePDF(EventApplication @event) { // initialize the file name string filename = "application" + @event.Id + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".pdf"; filename = Path.Combine(Server.MapPath("~/Applications/"), filename); Document document = new Document(PageSize.A4, 72, 65, 72, 65); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(filename, FileMode.Create)); document.AddAuthor("Planeta Hub"); document.AddTitle("Подання на проведення заходу"); document.AddCreationDate(); string sylfaenpath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\sylfaen.ttf"; BaseFont sylfaen = BaseFont.CreateFont(sylfaenpath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font head = new Font(sylfaen, 14f, Font.NORMAL, BaseColor.BLUE); Font normal = new Font(sylfaen, 14f, Font.NORMAL, BaseColor.BLACK); Font bold = new Font(sylfaen, 14f, Font.BOLD, BaseColor.BLACK); document.Open(); Paragraph toWho = new Paragraph("Проректору з навчально-виховної роботи\nКиївського національного університету ім. Т. Шевченка\nШамраю Володимиру Анатолійовичу", normal); toWho.Alignment = 2; //makes text left aligned document.Add(toWho); Paragraph fromWho = new Paragraph("", normal); fromWho.Alignment = 2; document.Add(fromWho); document.Add(new Paragraph("\n\nПодання\n\n", normal) { Alignment = 1 }); string text = string.Format("Просимо дозволу провести {0} у диско-клубі \"Планета\" з {1:dd.MM.yyyy hh:mm} по {2:dd.MM.yyyy hh:mm}", @event.Name, @event.From, @event.Till); Paragraph body = new Paragraph(text, normal); document.Add(body); string signature = "\n\n________________ Шамрай Володимир Анатолійович"; Paragraph ending = new Paragraph(signature, bold); ending.Alignment = 2; document.Add(ending); string responsible = "Відповідальні:\n"; Paragraph resp1 = new Paragraph(responsible, normal); document.Add(resp1); Paragraph resp2 = new Paragraph("Заславська Інга", bold); document.Add(resp2); responsible = "студентка філософського факультету, напрямку культурологія ІІІ курс\nтел. 050 440 19 05"; Paragraph resp3 = new Paragraph(responsible, normal); document.Add(resp3); document.Close(); return filename; }