public IHttpActionResult Create(IconCreateViewModel model) { var response = ResponseModelFactory.CreateInstance; if (model.Code.Trim().Length <= 0) { response.SetFailed("请输入图标名称"); return(Ok(response)); } using (_dbContext) { if (_dbContext.Icons.Count(x => x.Code == model.Code) > 0) { response.SetFailed("图标已存在"); return(Ok(response)); } var entity = _mapper.Map <IconCreateViewModel, Icon>(model); entity.CreatedOn = DateTime.Now; entity.CreatedByUserId = AuthContextService.CurrentUser.UserId; entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName; _dbContext.Icons.Add(entity); _dbContext.SaveChanges(); response.SetSuccess(); return(Ok(response)); } }
public IHttpActionResult Create(PermissionCreateViewModel model) { var response = ResponseModelFactory.CreateInstance; if (model.Name.Trim().Length <= 0) { response.SetFailed("请输入权限名称"); return(Ok(response)); } using (_dbContext) { if (_dbContext.Permissions.Count(x => x.ActionCode == model.ActionCode && x.MenuId == model.MenuId) > 0) { response.SetFailed("权限操作码已存在"); return(Ok(response)); } var entity = _mapper.Map <PermissionCreateViewModel, Permission>(model); entity.CreatedOn = DateTime.Now; entity.Code = RandomHelper.GetRandomizer(8, true, false, true, true); entity.CreatedByUserId = AuthContextService.CurrentUser.UserId; entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName; _dbContext.Permissions.Add(entity); _dbContext.SaveChanges(); response.SetSuccess(); return(Ok(response)); } }
// [ProducesResponseType(200)] public IHttpActionResult Create(UserCreateViewModel model) { var response = ResponseModelFactory.CreateInstance; if (model.LoginName.Trim().Length <= 0) { response.SetFailed("请输入登录名称"); return(Ok(response)); } using (_dbContext) { if (_dbContext.Users.Count(x => x.LoginName == model.LoginName) > 0) { response.SetFailed("登录名已存在"); return(Ok(response)); } var entity = _mapper.Map <UserCreateViewModel, User>(model); entity.CreatedOn = DateTime.Now; entity.Status = model.Status; entity.CreatedByUserId = AuthContextService.CurrentUser.UserId; _dbContext.Users.Add(entity); _dbContext.SaveChanges(); response.SetSuccess(); return(Ok(response)); } }
public IHttpActionResult PutTjCustomer(int id, TjCustomer tjCustomer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tjCustomer.Id) { return(BadRequest()); } db.Entry(tjCustomer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TjCustomerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Create(RoleCreateViewModel model) { var response = ResponseModelFactory.CreateInstance; if (model.Name.Trim().Length <= 0) { response.SetFailed("请输入角色名称"); return(Ok(response)); } using (_dbContext) { // if (_dbContext.Roles.Count(x => x.Name == model.Name) > 0) { if (_dbContext.Roles.Any(x => x.Name == model.Name)) { response.SetFailed("角色已存在"); return(Ok(response)); } var entity = _mapper.Map <RoleCreateViewModel, Role>(model); entity.CreatedOn = DateTime.Now; entity.Code = RandomHelper.GetRandomizer(8, true, false, true, true); entity.IsSuperAdministrator = false; entity.IsBuiltin = false; entity.CreatedByUserId = AuthContextService.CurrentUser.UserId; entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName; _dbContext.Roles.Add(entity); _dbContext.SaveChanges(); response.SetSuccess(); return(Ok(response)); } }
public IHttpActionResult Create(TjCustomer customer) { var response = ResponseModelFactory.CreateInstance; using (_dbContext) { customer.Owner = AuthContextService.CurrentUser.UserId; _dbContext.TjCustomers.Add(customer); _dbContext.SaveChanges(); } response.SetSuccess(); return(Ok(response)); }
//[ProducesResponseType(200)] public IHttpActionResult Create(MenuCreateViewModel model) { using (_dbContext) { var entity = _mapper.Map <MenuCreateViewModel, Menu>(model); entity.CreatedOn = DateTime.Now; entity.Guid = Guid.NewGuid(); entity.CreatedByUserId = AuthContextService.CurrentUser.UserId; entity.CreatedByUserName = AuthContextService.CurrentUser.DisplayName; _dbContext.Menus.Add(entity); _dbContext.SaveChanges(); var response = ResponseModelFactory.CreateInstance; response.SetSuccess(); return(Ok(response)); } }
public string bc() { string json = File.ReadAllText(@"c:\Users\Administrator\Documents\customer.txt", Encoding.UTF8); var list = JsonConvert.DeserializeObject <List <JObject> >(json); var customers = from jo in list select new TjCustomer { Name = jo["name"].ToString(), Email = jo["email"].ToString(), Phone = jo["phone"].ToString(), Company = jo["company"].ToString(), Region = jo["region"].ToString(), Location = jo["location"].ToString(), Industry = jo["industry"].ToString(), Owner = 0, ServiceBy = 0 }; var db = new ErpDbContext(); db.TjCustomers.AddRange(customers); db.SaveChanges(); return("ok"); }
public IHttpActionResult Create(TjSku model) { var response = ResponseModelFactory.CreateInstance; if (model.SkuCode.Trim().Length <= 0) { response.SetFailed("请输入物料编码"); return(Ok(response)); } using (_dbContext) { if (_dbContext.TjSkus.Any(x => x.SkuCode == model.SkuCode)) { response.SetFailed($"{model.SkuType}的物料编码{model.SkuCode}已经存在!"); return(Ok(response)); } var entity = new TjSku { SkuCode = model.SkuCode, SkuType = model.SkuType, CName = model.CName, EName = model.EName }; _dbContext.TjSkus.Add(entity); _dbContext.SaveChanges(); response.SetSuccess(); return(Ok(response)); } }