public DeUser Save(DeUser obj) { if (GetByCode(obj.UserCode) == null) { using (MySqlConnection conn = GetConnection()) { conn.Open(); var script = $"INSERT INTO `User` (`UserCode`, `Password`, `Name`, `LastName`, `Email`, `CountryCode`, `StateCode`, `Imagepath`, `BirthDate`, `Gender`) VALUES ('{obj.UserCode}', '{obj.Password}', '{obj.Name}', '{obj.LastName}', '{obj.Email}', '{obj.CountryCode}', '{obj.StateCode}', '{obj.ImagePath}', '{obj.BirthDate.ToString("yyyyMMdd")}', '{obj.Gender}');"; MySqlCommand cmd = new MySqlCommand(script, conn); cmd.ExecuteNonQuery(); } } else { using (MySqlConnection conn = GetConnection()) { conn.Open(); //var script = $"UPDATE `User` SET `Password` = '{obj.Password}', `Name`= '{obj.Name}', `LastName`= '{obj.LastName}', `Email`= '{obj.Email}', `CountryCode`= '{obj.CountryCode}', `StateCode`= '{obj.StateCode}', `ImagePath`= '{obj.ImagePath}', `BirthDate`='{obj.BirthDate.ToString("yyyyMMdd")}', `IsAdmin`='{Convert.ToInt32(obj.IsAdmin)}' WHERE `UserCode` = '{obj.UserCode}';"; var script = $"UPDATE `User` SET `Password` = '{obj.Password}', `Name`= '{obj.Name}', `LastName`= '{obj.LastName}', `Email`= '{obj.Email}', `CountryCode`= '{obj.CountryCode}', `StateCode`= '{obj.StateCode}', `ImagePath`= '{obj.ImagePath}', `BirthDate`='{obj.BirthDate.ToString("yyyyMMdd")}' WHERE `UserCode` = '{obj.UserCode}';"; MySqlCommand cmd = new MySqlCommand(script, conn); cmd.ExecuteNonQuery(); } } return(obj); }
public static ApiResponse GetByCode(string code) { var result = new ApiResponse(); try { var usr = new DlUser().GetByCode(code); if (usr != null) { result = new ApiResponse(true, "", usr); } else { usr = new DeUser { UserCode = "", Name = "", LastName = "", Email = "", Password = "", ImagePath = "", BirthDate = DateTime.Today }; } result = new ApiResponse(true, "New User", usr); } catch (Exception ex) { result = new ApiResponse(false, ex.Message, null); } return(result); }
public static ApiResponse Save(DeUser obj) { var result = new ApiResponse(); try { new DlUser().Save(obj); result = new ApiResponse(true, "", 1); } catch (Exception ex) { result = new ApiResponse(false, ex.Message, null); } return(result); }