/// <summary> /// Create new /// </summary> /// <param name="tEntity"></param> /// <returns></returns> public TEntity Create(TEntity tEntity) { var newEntry = DbSet.Add(tEntity); //if (ShareContext) context.SaveChanges(); return(newEntry); }
/// <summary> /// /// </summary> /// <returns></returns> public int Save() { try { return(_context.SaveChanges()); } catch (OptimisticConcurrencyException ex) { throw ex; } }
}/// <summary> /// Insert A new company Using Custom Stored Procedure /// </summary> /// <param name="companyVm"></param> /// <returns></returns> public int Insert(CompanyVM companyVm) { int result = 0; try { using (var context = new CMS_DbEntities()) { context.Tbl_Company.Add(converter.ConvertToEntity(companyVm)); //will execute UserSP_InsertCompany context.SaveChanges(); } } catch (Exception ex) { throw; } return(result); }
/// <summary> /// Update existing Company details /// </summary> /// <param name="companyVm"></param> /// <returns></returns> public int Update(CompanyVM companyVm) { int result = 0; try { using (var context = new CMS_DbEntities()) { Tbl_Company company = context.UserSP_CompanyById(companyVm.ID).FirstOrDefault(); converter.ConvertToEntity(companyVm, company); //will execute UserSP_UpdateCompany context.SaveChanges(); } } catch (Exception ex) { throw; } return(result); }
/// <summary> /// ///delete for end user but changing Delete column /// </summary> /// <param name="id"></param> /// <returns></returns> public int Delete(object id) { int result = 0; try { using (var context = new CMS_DbEntities()) { //Get company using SP UserSP_CompanyById Tbl_Company company = context.UserSP_CompanyById((int)id).FirstOrDefault(); // my storeprocedure change delete status in database for Delete context.Tbl_Company.Remove(company); //will execute sp_DeleteStudentInfo context.SaveChanges(); } } catch (Exception ex) { throw; } return(result); }