Пример #1
0
        protected ActionResult SaveSite(ImportSitesModel model, Trip trip, int siteId, bool saveUnlessOptionalErrors)
        {
            var siteModel = model.FindSiteById(siteId);
            var site      = trip.FindSiteById(siteId);

            Mapper.Map(siteModel, site);

            string modelPrefix = $"Sites[{model.Sites.IndexOf(siteModel)}].";

            this.ValidateMappedModel <Site, ImportSiteModel>(site, modelPrefix, ValidationTag.Required);
            if (!ModelState.IsValid)
            {
                return(Request.IsAjaxRequest() ?
                       PartialView("SitePartial", model).AddViewData("siteId", site.Id) : View(model));
            }

            this.ValidateMappedModel <Site, ImportSiteModel>(site, modelPrefix, ValidationTag.Optional);
            if (!ModelState.IsValid && saveUnlessOptionalErrors)
            {
                siteModel.HasOptionalError = true;
                model.HasOptionalErrors    = true;
                return(Request.IsAjaxRequest() ?
                       PartialView("SitePartial", model).AddViewData("siteId", site.Id) : View(model));
            }

            site.SetTripDefaults();
            Repositories.Imports.Save(trip);
            Uow.Persist();

            siteModel.IsEditing = false;
            return(Request.IsAjaxRequest() ?
                   PartialView("SitePartial", model).AddViewData("siteId", site.Id) : View(model));
        }
Пример #2
0
        protected ActionResult EditSite(ImportSitesModel model, Trip trip, int siteId)
        {
            var site = model.FindSiteById(siteId);

            site.IsEditing = true;

            return(Request.IsAjaxRequest() ?
                   PartialView("SitePartial", model).AddViewData("siteId", site.Id) : View(model));
        }
Пример #3
0
        protected ActionResult RemoveSite(ImportSitesModel model, Trip trip, int siteId)
        {
            var site = trip.FindSiteById(siteId);

            trip.RemoveSite(site);
            Repositories.Imports.Save(trip);
            Uow.Persist();

            var siteModel = model.FindSiteById(site.Id);

            model.RemoveSite(siteModel);
            model.Initialize();

            return(Request.IsAjaxRequest() ?
                   PartialView("SitesPartial", model) : (ActionResult)View(model));
        }