Ejemplo n.º 1
0
        public ActionResult Create([DataSourceRequest] DataSourceRequest request, ViewModel model)
        {
            var garage = this.garageAdministrationService.Read().FirstOrDefault(c => c.Id == model.GarageId);
            var user   = this.userAdministrationService.Read().FirstOrDefault(u => u.Id == model.UserId);

            if (garage == null || user == null)
            {
                if (garage == null)
                {
                    this.ModelState.AddModelError("GarageId", "Invalid_garage");
                }

                if (user == null)
                {
                    this.ModelState.AddModelError("UserId", "Invalid_user");
                }

                return(this.GridOperation(model, request));
            }

            var dbClient = Mapper.Map <Client>(model);

            dbClient.User   = user;
            dbClient.Garage = garage;

            this.clientAdministrationService.Create(dbClient);
            var addedClient = this.clientAdministrationService.Get(dbClient.Id);

            model.Id         = addedClient.Id;
            model.UserName   = user.UserName;
            model.GarageName = garage.Name;

            return(this.GridOperation(model, request));
        }
Ejemplo n.º 2
0
        public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                this.clientAdministrationService.Delete(model.Id);
            }

            return(this.GridOperation(model, request));
        }
Ejemplo n.º 3
0
        //[HttpGet]
        //public FileResult ExportToExcelByGarage(DataSourceRequest request, Guid garageId)
        //{
        //    var data = ((IEnumerable<ViewModel>)this.clientAdministrationService.Read()).Where(p => p.GarageId == garageId);
        //    return this.ExportToExcel(request, data);
        //}

        protected JsonResult GridOperation(ViewModel model, [DataSourceRequest] DataSourceRequest request)
        {
            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }