/// <summary> /// 创建一条随机生成的车辆记录 /// </summary> /// <returns></returns> public ActionResult CreateRandomVehicle() { if (vehicleService.Create(VehicleService.GetRandomVehicle())) { Response.Write("<script>alert('添加完成')</script>"); } else { Response.Write("<script>alert('添加失败')</script>"); } return(View("MainPage")); }
/// <summary> /// 创建一条新的车辆信息 /// </summary> /// <returns></returns> public ActionResult CreateVehicle() { string type = Request["Type"]; if ("Micro".Equals(type)) { type = "小型货车"; } else if ("Small".Equals(type)) { type = "中型货车"; } else if ("Large".Equals(type)) { type = "大型货车"; } else if ("Heavy".Equals(type)) { type = "重型货车"; } modelService.Create(new Vehicle() { License = VehicleService.GetRandomLicense(), Type = type, Height = float.Parse(Request["Height"].ToString()), Weight = float.Parse(Request["Weight"].ToString()), Load = float.Parse(Request["load"].ToString()) }); ViewBag.list = VehicleService.GetAllVehcleInfo(); return(View("VehicleInfo")); }
public IActionResult Create(VehicleModelVM model) { try { var modelForCreation = mapper.Map <Model>(model); if (ModelState.IsValid) { modelService.Create(modelForCreation); return(RedirectToAction("Detail", "Model", new { id = modelForCreation.Id })); } else { var createModel = new CreateModel { Abrv = model.Abrv, MakeId = model.MakeId, DetailMakeName = model.DetailMakeName }; return(View(createModel)); } } catch (Exception) { return(BadRequest()); } }
public ActionResult Add(Product product) { try { if (string.IsNullOrEmpty(product.Name)) { ErrorView error = new ErrorView() { message = EmptyProductName }; return(View("Error", error)); } product.Specifications = GetSpecifications(product); var orignpics = GetPictures(product); product.OwnerID = GetOwnerID(); product.ProductPictures = orignpics; svc.Create(product); if (orignpics.Count > 0) { var newpics = new ProductPicture[orignpics.Count()]; for (int i = 0; i < orignpics.Count(); i++) { ProductPicture pic = new ProductPicture() { ID = orignpics[i].ID, Name = orignpics[i].Name, Path = MakePath(product.ID.Value), }; newpics[i] = pic; } svc.Update(newpics); _pictureService.Move(orignpics.ToArray(), newpics); } return(RedirectToAction("Index")); } catch (Exception e) { ErrorView error = new ErrorView() { message = e.Message }; return(View("Error", error)); } }
public ActionResult Create(Product product) { productServise.Create(prod); try { // TODO: Add insert logic here return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IActionResult> PostCreate(Model model) { if (!ModelState.IsValid) { return(BadRequest(ModelState.ValidationState)); } var result = await _modelService.Create(model); if (result) { return(Ok()); } return(BadRequest()); }
public async Task <ActionResult <ModelRes> > Create([FromBody] SaveModelRes saveModelRes) { var validator = new SaveModelValidator(); var validationResult = await validator.ValidateAsync(saveModelRes); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } var create = await _service.Create(_mapper.Map <SaveModelRes, Model>(saveModelRes)); var model = await _service.GetById(create.ModelId); var resource = _mapper.Map <Model, ModelRes>(model); return(Ok(resource)); }
public ActionResult Index(WeChatAccount account) { try { if (account.ID == null) { svc.Create(account); } else { svc.Update(account); } ViewBag.Url = account.Url; ViewBag.Token = account.Token; return(View(account)); } catch (RuleViolatedException e) { ViewBag.Error = e.Message; ViewBag.Url = account.Url; ViewBag.Token = account.Token; return(View(account)); } }
/// <summary> /// 统一处理图片上传工作 /// </summary> /// <param name="res">需要返回的操作结果</param> /// <param name="picType">带处理的图片类型</param> /// <returns>操作结果</returns> public JsonResult DoUpload(int picType) { JsonResult result = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet, ContentType = "text/html" }; try { var pics = GetUploadPictures(picType).ToArray(); if (!pics.Any()) { result.Data = new { success = false, Message = "文件列表为空" } } ; else { List <BannerPicture> _List = new List <BannerPicture>(); foreach (var item in pics.ToList()) { item.Name = DateTime.Now.ToString("yyMMdd_HHmmss_") + item.Name; _pictureService.Create(item); svc.Create(item); var fullpath = Path.Combine(ftp, item.Path, item.Name); BannerPicture _item = item; _item.Path = fullpath; _List.Add(_item); } //清空Content,否则反序列化时会因数据太大而失败 foreach (var item in _List) { item.Content = null; } result.Data = new { success = true, picList = _List }; } return(result); } catch (PicTypeException e) { //文件格式不正确,提示错误时,需还原成本地文件名称,去除区分同名文件所加上的时间戳字符串 result.Data = new { success = false, Message = string.Format(PicTypeError, e.pic.Name.Substring(14)) }; return(result); } catch (PicSizeException e) { //文件大小超出,提示错误时,需还原成本地文件名称,去除区分同名文件所加上的时间戳字符串 result.Data = new { success = false, Message = string.Format(PicSizeError, e.pic.Name.Substring(14)) }; return(result); } catch (Exception e) { result.Data = new { success = false, Message = e.Message }; return(result); } }
public void Post(ModelViewModel model) { _modelService.Create(model); }
/// <summary> /// 创建一个随机雇员信息 /// </summary> /// <returns></returns> public bool CreateRandomEmployee() { return(employeeService.Create(EmployeeService.GetRandomEmployee())); }
public ActionResult AddRule(Rule rule) { svc.Create(rule); return(RedirectToAction("Index")); }