Exemplo n.º 1
0
        public static ViewModels.Press CopyToViewModel(this DomainModels.Press domainModel, ViewModels.Press viewModel = null)
        {
            if (viewModel == null)
            {
                viewModel = new ViewModels.Press();
            }

            viewModel.ID      = domainModel.ID;
            viewModel.Name    = domainModel.Name;
            viewModel.Address = domainModel.Address;
            viewModel.Contact = domainModel.Contact;

            return(viewModel);
        }
Exemplo n.º 2
0
        public static DomainModels.Press CopyToDomainModel(this ViewModels.Press viewModel, DomainModels.Press domainModel = null)
        {
            if (domainModel == null)
            {
                domainModel = new DomainModels.Press();
            }

            domainModel.ID      = viewModel.ID;
            domainModel.Name    = viewModel.Name;
            domainModel.Address = viewModel.Address;
            domainModel.Contact = viewModel.Contact;
            domainModel.State   = viewModel._state.Equals("added", StringComparison.CurrentCultureIgnoreCase) ? DomainModels.EntityState.Add :
                                  viewModel._state.Equals("modified", StringComparison.CurrentCultureIgnoreCase) ? DomainModels.EntityState.Modify : DomainModels.EntityState.Delete;

            return(domainModel);
        }
Exemplo n.º 3
0
        public ActionResult SaveChanges(IEnumerable <ViewModels.Press> changedPresses)
        {
            var service = ResolveService <IPressService>();
            List <DomainModels.Press> pressesToSave = new List <DomainModels.Press>();

            foreach (var press in changedPresses)
            {
                DomainModels.Press pressToSave = new DomainModels.Press();
                if (press._state.Equals("modified", StringComparison.CurrentCultureIgnoreCase))
                {
                    pressToSave = service.GetById(press.ID);
                }

                pressesToSave.Add(press.CopyToDomainModel(pressToSave));
            }
            service.SaveChanges(pressesToSave);

            return(Json(new JsonResultData
            {
                Success = true
            }));
        }