public ActionResult Create(OrganizationModel model)
        {
            var org_service = CompositionRoot.Resolve <IOrganizationService>();

            if (ModelState.IsValid)
            {
                bool has_error = false;

                try {
                    var org = OrganizationModelConverter.FromModel(model);
                    org_service.CreateOrganization(model.Caption, model.FullCaption, model.TypeId);
                }
                catch (DomainException e) {
                    ModelState.AddModelError("", e);
                    has_error = true;
                }

                if (!has_error)
                {
                    return(RedirectToAction("List"));
                }
            }

            var types = new List <OrganizationTypeModel>();

            foreach (var type in org_service.GetAllTypes())
            {
                types.Add(OrganizationTypeModelConverter.ToModel(type));
            }

            ViewBag.OrganizationTypes = types;

            return(View("Edit", model));
        }
        public ActionResult List()
        {
            var org_service = CompositionRoot.Resolve <IOrganizationService>();

            List <OrganizationModel> items = new List <OrganizationModel>();

            foreach (var entity in org_service.GetAllOrganizations())
            {
                items.Add(OrganizationModelConverter.ToModel(entity));
            }

            return(View(items));
        }
        public ActionResult ListData()
        {
            var org_service = CompositionRoot.Resolve <IOrganizationService>();

            List <OrganizationModel> items = new List <OrganizationModel>();

            foreach (var entity in org_service.GetAllOrganizations())
            {
                items.Add(OrganizationModelConverter.ToModel(entity));
            }

            return(Json(items, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Delete(int id)
        {
            var organization_service = CompositionRoot.Resolve <IOrganizationService>();

            var org = organization_service.GetOrganizationById(id);

            if (org == null)
            {
                ModelState.AddModelError("", "ОГВ не найдена");
                return(RedirectToAction("List"));
            }

            var model = OrganizationModelConverter.ToModel(org);

            return(View(model));
        }
        public ActionResult Create()
        {
            var srv     = CompositionRoot.Resolve <IServiceService>();
            var org_srv = CompositionRoot.Resolve <IOrganizationService>();

            var orgs = new List <OrganizationModel>();

            foreach (var type in org_srv.GetAllOrganizations())
            {
                orgs.Add(OrganizationModelConverter.ToModel(type));
            }

            ViewBag.Organizations = orgs;

            return(View("Edit", new ServiceModel()));
        }
        public ActionResult Edit(int id)
        {
            var org_service = CompositionRoot.Resolve <IOrganizationService>();
            var org         = org_service.GetOrganizationById(id);

            if (org == null)
            {
                ModelState.AddModelError("", string.Format("ОГВ с кодом {0} не найдена в базе данных", id));
                return(View());
            }

            var types = new List <OrganizationTypeModel>();

            foreach (var type in org_service.GetAllTypes())
            {
                types.Add(OrganizationTypeModelConverter.ToModel(type));
            }

            ViewBag.OrganizationTypes = types;

            return(View(OrganizationModelConverter.ToModel(org)));
        }
        public ActionResult Edit(int id)
        {
            var srv     = CompositionRoot.Resolve <IServiceService>();
            var service = srv.GetServiceById(id);

            if (service == null)
            {
                ModelState.AddModelError("", string.Format("Услуга с кодом {0} не найдена в базе данных", id));
                return(View());
            }

            var org_srv = CompositionRoot.Resolve <IOrganizationService>();

            var orgs = new List <OrganizationModel>();

            foreach (var type in org_srv.GetAllOrganizations())
            {
                orgs.Add(OrganizationModelConverter.ToModel(type));
            }

            ViewBag.Organizations = orgs;

            return(View(ModelConverter.ToModel(service)));
        }
        public ActionResult Create(ServiceModel model)
        {
            var srv = CompositionRoot.Resolve <IServiceService>();

            if (ModelState.IsValid)
            {
                bool has_error = false;

                try {
                    var org = ModelConverter.FromModel(model);
                    srv.Create(model.Caption, model.OrgId);
                }
                catch (DomainException e) {
                    ModelState.AddModelError("", e);
                    has_error = true;
                }

                if (!has_error)
                {
                    return(RedirectToAction("List"));
                }
            }

            var org_srv = CompositionRoot.Resolve <IOrganizationService>();

            var orgs = new List <OrganizationModel>();

            foreach (var type in org_srv.GetAllOrganizations())
            {
                orgs.Add(OrganizationModelConverter.ToModel(type));
            }

            ViewBag.Organizations = orgs;

            return(View("Edit"));
        }