public IHttpActionResult SignUp([FromBody] m_Users request) { if (ModelState.IsValid) { try { if (!Auth.checkHaveSerialNumber(request.serial_number)) { if (!Auth.checkHaveUser(request.username)) { var qry = _Users.UserCreate(request); if (qry != null) { return(Json(qry)); } return(BadRequest("Create user failed.")); } return(BadRequest("have username in system.")); } return(BadRequest("have serial number in system.")); } catch (Exception ex) { return(BadRequest(ex.Message)); } } return(BadRequest("Model is incorrect.")); }
public users UserCreate(m_Users request) { request.password = Convert.ToBase64String(Encoding.UTF8.GetBytes(request.password)); var qry = db.Database.SqlQuery <users>("EXEC [farmnet].[s_Users_Create] @firstname,@lastname,@email,@username,@password,@serial_number,@user_type_id,@house_no,@village_no,@sub_area,@area,@province,@postal_code", new SqlParameter("@firstname", request.firstname), new SqlParameter("@lastname", request.lastname), new SqlParameter("@email", request.email), new SqlParameter("@username", request.username), new SqlParameter("@password", request.password), new SqlParameter("@serial_number", request.serial_number), new SqlParameter("@user_type_id", request.user_type_id), new SqlParameter("@house_no", request.house_no), new SqlParameter("@village_no", request.village_no), new SqlParameter("@sub_area", request.sub_area), new SqlParameter("@area", request.area), new SqlParameter("@province", request.province), new SqlParameter("@postal_code", request.postal_code) ).FirstOrDefault(); if (qry != null) { return(qry); } return(null); }
public users UserEdit(m_Users request, int Id) { var qry = db.Database.SqlQuery <users>("EXEC [farmnet].[s_Users_Edit] @Id,@firstname,@lastname,@email,@username,@password,@serial_number,@lat,@lng,@user_type_id", new SqlParameter("@Id", Id), new SqlParameter("@firstname", request.firstname), new SqlParameter("@lastname", request.lastname), new SqlParameter("@email", request.email), new SqlParameter("@username", request.username), new SqlParameter("@password", request.password), new SqlParameter("@serial_number", request.serial_number), new SqlParameter("@user_type_id", request.user_type_id) ).FirstOrDefault(); if (qry != null) { return(qry); } return(null); }