public static CarParkServiceModel MapToCarParkServiceModel(this CarParkViewModel model) { return(new CarParkServiceModel { IdCarPark = model.IdCarPark, NameCarPark = model.NameCarPark, Bays = model.Bays.Select(bay => new BayServiceModel { BayCount = bay.BayCount, BayType = bay.BayType, Free = bay.Free, Occupied = bay.Occupied }) }); }
public IHttpActionResult Create([FromBody] CarParkViewModel model) { CarParkApi carParkApi = new CarParkApi(); try { carParkApi.Create(model); return(Json(new { success = true, })); } catch (Exception ex) { return(Json(new { success = false, })); } }
public IActionResult Edit(CarParkViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { var entity = _dbContext.CarPark.FirstOrDefault(x => x.CarParkUuid == model.CarParkUuid); if (entity == null) { response.SetFailed("不存在"); return(Ok(response)); } if (_dbContext.CarPark.Count(x => x.Name == model.Name && x.CarParkUuid != model.CarParkUuid) > 0) { response.SetFailed("名称已存在"); return(Ok(response)); } entity.Name = model.Name; entity.Specification = model.Specification; entity.Lon = model.Lon; entity.Lat = model.Lat; entity.TruckSpace = model.TruckSpace; entity.ChargesNotes = model.ChargesNotes; entity.CreateTime = Convert.ToDateTime(model.CreateTime); entity.Address = model.Address; entity.Price = model.Price; entity.Picture = model.Picture; entity.State = model.State; int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("编辑", "成功:编辑:停车场列表信息数据", _dbContext); } response = ResponseModelFactory.CreateInstance; return(Ok(response)); } }
public IActionResult Create(CarParkViewModel model) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { if (_dbContext.CarPark.Count(x => x.Name == model.Name) > 0) { response.SetFailed("名称已存在"); return(Ok(response)); } var entity = new CarPark(); entity.Name = model.Name; entity.Specification = model.Specification; entity.Lon = model.Lon; entity.Lat = model.Lat; entity.TruckSpace = model.TruckSpace; entity.ChargesNotes = model.ChargesNotes; entity.CreateTime = Convert.ToDateTime(model.CreateTime); entity.Address = model.Address; entity.Price = model.Price; entity.Picture = model.Picture; entity.State = model.State; //var entity = _mapper.Map<CarParkViewModel, CarPark>(model); entity.CarParkUuid = Guid.NewGuid(); entity.IsDelete = 0; _dbContext.CarPark.Add(entity); int res = _dbContext.SaveChanges(); if (res > 0) { ToLog.AddLog("添加", "成功:添加:停车场列表信息数据", _dbContext); } response.SetSuccess(); return(Ok(response)); } }