public void Remove(DomainModels.DTO.EF.Customer ref_Customer) { using (var context = new DomainModels.DTO.EF.OnlineShopEntities()) { try { var itemToRemove = context.Customer.SingleOrDefault(x => x.Id == ref_Customer.Id); if (itemToRemove != null) { context.Customer.Remove(itemToRemove); context.SaveChanges(); } } catch (Exception) { throw; } finally { if (context != null) { context.Dispose(); } } } }
public void Update(DomainModels.DTO.EF.Customer ref_Customer) { using (var context = new DomainModels.DTO.EF.OnlineShopEntities()) { try { var itemToUpdate = context.Customer.SingleOrDefault(x => x.Id == ref_Customer.Id); if (itemToUpdate != null) { context.Entry(itemToUpdate).CurrentValues.SetValues(ref_Customer); context.SaveChanges(); } } catch (Exception) { throw; } finally { if (context != null) { context.Dispose(); } } } }
public void Insert(DomainModels.DTO.EF.Customer ref_Customer) { using (var context = new DomainModels.DTO.EF.OnlineShopEntities()) { try { context.Customer.Add(ref_Customer); context.SaveChanges(); } catch (Exception) { throw; } finally { if (context != null) { context.Dispose(); } } } }
public string SelectCustomerNameGivenId(DomainModels.DTO.EF.Customer ref_Customer) { using (var context = new DomainModels.DTO.EF.OnlineShopEntities()) { try { var id = new SqlParameter("id", SqlDbType.Int); id.Value = ref_Customer.Id; var firstName = new SqlParameter(); firstName.ParameterName = "firstName"; firstName.SqlDbType = SqlDbType.NVarChar; //size is important in nvarchar and varchar firstName.Size = 60; firstName.Direction = ParameterDirection.Output; var lastName = new SqlParameter(); lastName.ParameterName = "lastName"; lastName.SqlDbType = SqlDbType.NVarChar; lastName.Size = 60; lastName.Direction = ParameterDirection.Output; context.Database.ExecuteSqlCommand("exec dbo.usp_SelectCustomerNameGivenId @id, @firstName output,@lastName output", id, firstName, lastName); var result = (string)firstName.Value + " " + (string)lastName.Value; return(result); } catch (Exception) { throw; } finally { } } }