/// <summary> /// 转换为订单实体 /// </summary> /// <param name="dto">订单数据传输对象</param> public static Order ToEntity(this OrderDto dto) { if (dto == null) { return(new Order()); } return(dto.MapTo(new Order(dto.Id.ToGuid()))); }
public Result Add(OrderDto dto) { try { var list = dto.MapTo <OrderEntity>(); var result = UnitOfWorkService.Execute(() => _orderRepository.InsertAndGetId(list)); if (result.IsNullOrEmpty()) { return(new Result(false, "数据库操作失败")); } return(new Result(true, "")); } catch (Exception ex) { Logger.Error("Order Add", ex); return(new Result(false, "添加失败")); } }
public Result Update(OrderDto dto) { try { var list = dto.MapTo <OrderEntity>(); var result = UnitOfWorkService.Execute(() => _orderRepository.Update(list)); if (!result) { return(new Result(false, "数据库操作失败")); } return(new Result(true, "")); } catch (Exception ex) { Logger.Error("Order update", ex); return(new Result(false, "修改失败")); } }
public ActionResult Order(OrderDto model) { if (ModelState.IsValid) { try { // 选择日期的对应类型与套餐是否存在 var menu = _repo.Single <Menu>(x => x.MenuDate == model.MenuDate && x.MenuType == (MenuTypeEnum)Enum.Parse(typeof(MenuTypeEnum), model.MenuName) && // ReSharper disable once RedundantBoolCompare // Shsict.Core.ConditionBuilder x.MenuFlag == model.Flag && x.IsActive == true); if (menu == null) { ModelState.AddModelError("Error", "所选日期不存在对应类型的套餐,无法添加或修改"); return(View(model)); } var order = _repo.Single <Order>(model.ID); if (order == null) { // 新增订餐记录 order = model.MapTo <OrderDto, Order>(); order.IsActive = true; order.Remark = "后台补订"; } else { // 修改订餐记录 order.Remark = "后台修改"; } #region 设置用餐人信息 在UserName中传递UserGuid model.UserGuid = new Guid(model.UserName); var user = _repo.Single <User>(model.UserGuid); if (user != null) { order.UserGuid = user.ID; order.UserName = user.EmployeeName; order.EmployeeNo = user.EmployeeNo; } else { order.UserGuid = Guid.Empty; order.UserName = string.Empty; order.EmployeeNo = string.Empty; } #endregion order.MenuID = menu.ID; order.DeliveryGuid = new Guid(model.DeliveryPoint); order.StapleFood = (StapleFoodEnum)Enum.Parse(typeof(StapleFoodEnum), model.StapleFood); order.ExtraFood = model.ExtraFood; order.CreateUser = _authorizedUser.UserId; order.CreateTime = DateTime.Now; // 更新菜单信息 object key; _repo.Save(order, out key); ModelState.AddModelError("Success", "保存成功"); } catch (Exception ex) { ModelState.AddModelError("Warn", ex.Message); } } return(View(model)); }
public static Order ToEntity(this OrderDto model) { return(model.MapTo <OrderDto, Order>()); }
public static Order ToEntity(this OrderDto orderDto) { return(orderDto.MapTo <OrderDto, Order>()); }