لایه Service
namespace ServiceLayer.EFServices { public class TABMPCREWService : ITABMPCREWService { private IUnitOfWork _uow; private IDbSet<TABMPCREWS> _tabmpcrews; public TABMPCREWService(IUnitOfWork uow) { this._uow = uow; _tabmpcrews = uow.Set<TABMPCREWS>(); } public int Add(TABMPCREWS personnel) { int rowEffect = 0; _tabmpcrews.Add(personnel); rowEffect = _uow.SaveChanges(); return rowEffect; } } }
namespace ServiceLayer.Interface { public interface ITABMPCREWService { int Add(TABMPCREWS personnel); } }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); ObjectFactory.Initialize(x => { x.For<ITABMPCREWService>().Use<TABMPCREWService>(); // x.For<IUsersService>().Use<UsersService>(); }); ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory()); // initStructureMap(); }
public class StructureMapControllerFactory : DefaultControllerFactory { protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { if (controllerType == null) throw new InvalidOperationException(string.Format("Page not found: {0}", requestContext.HttpContext.Request.Url.AbsoluteUri.ToString(CultureInfo.InvariantCulture))); return ObjectFactory.GetInstance(controllerType) as Controller; } }
public class HomeController : Controller { public readonly ITABMPCREWService aa ; public HomeController(ITABMPCREWService tabmpcrewService) { aa = tabmpcrewService; } public ActionResult Index() { TABMPCREWS tt = new TABMPCREWS() { DTLASTUPDATEDDATE = DateTime.Now, INTOTRATE = 122, INTRATE = 215, VCCODEDESCRIPTION = "fff858699", VCCODEVALUE = "fff858699", VCLASTUSERID = "fff858699", INTCREWCODE = 105652 }; aa.Add(tt); ViewBag.Message = "Welcome to ASP.NET MVC!"; return View(); } public ActionResult About() { ViewBag.Message = "Your app description page."; return View(); } public ActionResult Contact() { ViewBag.Message = "Your contact page."; return View(); } }