public IHttpActionResult Post_CreateCheck([FromBody] m_check request) { try { var user = deCodeAuth.GetDeCodeAuthen(); var res = _Check.CreateCheck(request, user.Id); return(Json(res)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public Check CreateCheck(m_check input, int user_id) { if (db.v_CheckLottery.Count(c => c.lot_dt == input.lot_dt && c.Country_id == input.Country_id && c.user_id == user_id && c.Id.HasValue) == 0) { var add = db.Checks.Add(new Check { Country_id = input.Country_id, lot_dt = input.lot_dt, number_lower = input.number_lower, number_upper = input.number_upper, number_three = input.number_three, Create_dt = DateTime.Now, user_id = user_id }); var res = db.SaveChanges(); if (res > 0) { return(add); } throw new Exception("failed save to database"); } throw new Exception("Have your check lottery"); }