public static void CreateEvent() { if (IsAnyEventRunning) { Logger.LogTrivial(typeof(EventPool).Name, "Another event running. Aborting new event..."); return; } GameFiber.StartNew(delegate { IEvent ambientEvent = GetRandomEvent(); currentEvent = ambientEvent; if (ambientEvent.CanBeSpawned) { if (ambientEvent.Create()) { ambientEvent.Action(); } } }); }
public ActionResult Create(EventModel eventModel, FormCollection frm) { var invitees = new List <string>(); if (!string.IsNullOrEmpty(frm["invitees"])) { invitees = frm["invitees"].Split(',').ToList(); } eventModel.Date = DateTime.ParseExact(frm["Date"], "dd-MM-yyyy", CultureInfo.InvariantCulture); // String to datetime eventModel.End = DateTime.ParseExact(frm["End"], "dd-MM-yyyy", CultureInfo.InvariantCulture); // String to datetime if (!string.IsNullOrEmpty(frm["startTime"]) && frm["startTime"] != "Choose...") { var timearr = frm["startTime"].Split(':'); var time = new TimeSpan(int.Parse(timearr[0]), int.Parse(timearr[1]), 0); eventModel.Date = eventModel.Date.Add(time); } if (!string.IsNullOrEmpty(frm["endTime"]) && frm["endTime"] != "Choose...") { var timearr = frm["endTime"].Split(':'); var time = new TimeSpan(int.Parse(timearr[0]), int.Parse(timearr[1]), 0); eventModel.End = eventModel.End.Add(time); } var result = _eventManager.Create(eventModel, invitees); if (result != null) { if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { var fileName = Guid.NewGuid() + "_" + Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/images/"), fileName); file.SaveAs(path); var image = new SiteImage { ImagePath = "/Content/images/" + fileName, Type = "Event", TypeId = result.EventId, UploadDate = DateTime.Now, UploaderId = result.CreatorId }; _noticeBoardManager.SaveImage(image); } else { var image = new SiteImage { ImagePath = "/Content/images/Event/DefaultImage2.jpg", Type = "Event", TypeId = result.EventId, UploadDate = DateTime.Now, UploaderId = result.CreatorId }; _noticeBoardManager.SaveImage(image); } } return(RedirectToAction("Index")); } return(View()); }
public IActionResult New([FromForm] IFormCollection form, [FromForm] IFormFile picFile) //string name, string surname, string email, string telephone, string password) { int creatorId = int.Parse(Request.Cookies["user"]); var title = form["title"]; DateTime dateStart = DateTime.Parse(form["dateStart"]); DateTime dateEnd = DateTime.Parse(form["dateEnd"]); var city = form["city"]; var street = form["street"]; var houseNumber = int.Parse(form["houseNumber"]); var apartmentNumber = int.Parse(form["apartmentNumber"]); var postalCode = form["postalCode"]; var description = form["description"]; byte[] picture = null; BinaryReader reader = new BinaryReader(picFile.OpenReadStream()); picture = reader.ReadBytes((int)picFile.Length); int staticCategoryId = int.Parse(Request.Form["category"]); StaticCategory staticCategory = new StaticCategory(); staticCategory.Id = staticCategoryId; Event culturalEvent = new Event { Title = title, DateStart = dateStart, DateEnd = dateEnd, City = city, Street = street, HouseNumber = houseNumber, ApartmentNumber = apartmentNumber, PostalCode = postalCode, Description = description, Picture = picture, StaticCategory = staticCategory, CreatorId = creatorId }; try { //save _events.Create(culturalEvent, staticCategory); return(Redirect("/Events/Created")); } catch (Exception ex) { //return error if there was an exception return(BadRequest(new { message = ex.Message })); } /* * using (var transaction = _context.Database.BeginTransaction()) * { * * var list = _context.Categories.FromSql("SELECT * FROM dbo.Categories").ToList(); * transaction.Commit(); * } */ }