public OurClient GetClientById(long Id) { using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.GetClientById, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@Id", Id)); try { connection.Open(); SqlDataReader reader = command.ExecuteReader(); OurClient client = new OurClient(); client = UtilityManager.DataReaderMap <OurClient>(reader); return(client); } catch (Exception e) { throw new Exception("Exception retrieving reviews. " + e.Message); } finally { connection.Close(); } } }
public bool UpdateClient(OurClient client) { bool isUpdate = true; using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.UpdateClient, connection); command.CommandType = CommandType.StoredProcedure; foreach (var clients in client.GetType().GetProperties()) { string name = clients.Name; var value = clients.GetValue(client, null); command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value)); } try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception e) { isUpdate = false; throw new Exception("Exception Updating Data." + e.Message); } finally { connection.Close(); } } return(isUpdate); }
public async Task <IActionResult> Update(OurClient ourClient) { if (!ModelState.IsValid) { return(NotFound()); } OurClient dbourclient = _context.OurClients.FirstOrDefault(x => x.Id == ourClient.Id); if (ourClient != null) { IFormFileExtension.DeletePath(_env.WebRootPath, "images/clients", dbourclient.Image); dbourclient.Image = await ourClient.Photo.SaveImg(_env.WebRootPath, "images/clients"); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create(OurClient ourClient) { if (!ModelState.IsValid) { return(View()); } if (ModelState["Photo"].ValidationState == Microsoft.AspNetCore.Mvc.ModelBinding.ModelValidationState.Invalid) { return(View()); } if (!ourClient.Photo.IsImage()) { ModelState.AddModelError("Photo", "Shekilin olchusu max 1mg ola biler"); return(View()); } if (ourClient.Photo.MaxLength(1000)) { ModelState.AddModelError("Photo", "Shekilin olchusu max 1mg ola biler"); return(View()); } string path = Path.Combine("images", "clients"); string fileName = await ourClient.Photo.SaveImg(_env.WebRootPath, path); OurClient newClient = new OurClient { Image = fileName }; await _context.OurClients.AddAsync(newClient); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public long InsertClient(OurClient client) { long id = 0; using (SqlConnection connection = new SqlConnection(CommonUtility.ConnectionString)) { SqlCommand command = new SqlCommand(StoreProcedure.InsertClient, connection); command.CommandType = CommandType.StoredProcedure; SqlParameter returnValue = new SqlParameter("@" + "Id", SqlDbType.Int); returnValue.Direction = ParameterDirection.Output; command.Parameters.Add(returnValue); foreach (var clients in client.GetType().GetProperties()) { if (clients.Name != "Id") { string name = clients.Name; var value = clients.GetValue(client, null); command.Parameters.Add(new SqlParameter("@" + name, value == null ? DBNull.Value : value)); } } try { connection.Open(); command.ExecuteNonQuery(); id = (int)command.Parameters["@Id"].Value; } catch (Exception ex) { throw new Exception("Execption Adding Data. " + ex.Message); } finally { connection.Close(); } } return(id); }
public static long InsertClient(OurClient client) { SqlClientProvider provider = new SqlClientProvider(); return(provider.InsertClient(client)); }
public static bool UpdateClient(OurClient client) { SqlClientProvider provider = new SqlClientProvider(); return(provider.UpdateClient(client)); }