public string Create(EventModel eventEntity) { try { using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(Connectionstring)) { sqlConnection.Open(); string sqlQuery = "INSERT INTO Event(_EventType_key,EventID,EventName,ProjectedDate,ActualDate,_Workgroup_key,CreatedBy,DateCreated,ModifiedBy,DateModified) VALUES (@_EventType_key,@EventID,@EventName,@ProjectedDate,@ActualDate,@_Workgroup_key,@CreatedBy,@DateCreated,@ModifiedBy,@DateModified)"; sqlConnection.Execute(sqlQuery, new { eventEntity._EventType_key, eventEntity.EventID, eventEntity.EventName, eventEntity.ProjectedDate, eventEntity.ActualDate, eventEntity._Workgroup_key, eventEntity.CreatedBy, eventEntity.DateCreated, eventEntity.ModifiedBy, eventEntity.DateModified }); sqlConnection.Close(); } return "Created"; } catch (Exception ex) { return ex.Message; } }
public ActionResult Create(string eventType) { try { int eventKey=0; switch (eventType) { case "matingEvent": eventKey = 1; break; case "weanEvent": eventKey = 2; break; case "shipEvent": eventKey = 3; break; } var eventDB = new EventDB(); EventModel event_ = new EventModel(); event_._EventType_key = eventKey; event_.ActualDate = DateTime.Now; event_.CreatedBy="admin"; event_.DateCreated=DateTime.Now; event_.DateModified=DateTime.Now; event_.EventID="M1"; event_.EventName = eventType; event_.ModifiedBy = "admin"; event_.ProjectedDate=DateTime.Now; eventDB.Create(event_); return RedirectToAction("Index"); } catch { return View(); } }