public static AddNewsOutDTO AddNews(AddNewsInDTO inDto) { AddNewsOutDTO outDto = new AddNewsOutDTO(); try { if (inDto == null || string.IsNullOrEmpty(inDto.Title)) { outDto.ErrorMsg = "参数错误"; return(outDto); } if (inDto.Title.Length > 50) { outDto.ErrorMsg = "标题长度错误"; return(outDto); } //如果直接new也是可以的,目前是等效的,建议统一使用CreateObject,未来可以利用CreateObject搞一些事情 //News news = new News(); News news = PersisterService.CreateObject <News>(); news.SetId(TimeStampService.GetOneId <News>()); news.Title = inDto.Title; news.Context = inDto.Context; news.Author = inDto.Author; news.Type = inDto.Type; string remark = "增加新闻"; SystemLog systemLog = LogService.CreateSystemLog(SystemLogType.AddNews, typeof(News), news.Id, remark); PersisterService.SaveObject(new SRO[] { news, systemLog }); outDto.IsSucceed = true; outDto.Id = news.Id; } catch (Exception ex) { outDto.ErrorMsg = ex.Message; LogProxy.Error(ex, false); } return(outDto); }
public static AddUserOutDTO AddUser(AddUserInDTO inDto) { AddUserOutDTO outDto = new AddUserOutDTO(); try { if (inDto == null || string.IsNullOrEmpty(inDto.Name)) { outDto.ErrorMsg = "参数错误"; return(outDto); } //如果直接new也是可以的,目前是等效的,建议统一使用CreateObject,未来可以利用CreateObject搞一些事情 //User User = new User(); User user = PersisterService.CreateObject <User>(); user.SetId(TimeStampService.GetOneId <User>(inDto.Gender.ToString())); user.Name = inDto.Name; user.Gender = inDto.Gender; user.Mobile = inDto.Mobile; user.AvailableBalance = inDto.AvailableBalance; string remark = "增加用户"; SystemLog systemLog = LogService.CreateSystemLog(SystemLogType.AddUser, typeof(User), user.Id, remark); PersisterService.SaveObject(new SRO[] { user, systemLog }); outDto.IsSucceed = true; outDto.Id = user.Id; } catch (Exception ex) { outDto.ErrorMsg = ex.Message; LogProxy.Error(ex, false); } return(outDto); }