public async Task <IActionResult> Add([FromBody] NameDto nameDto) { if (!ModelState.IsValid) { return(this.ValidationError()); } Application application = this.GetApplication(); ApplicationService service = this.GetService(); Guid envKey = Guid.NewGuid(); try { await _defaultDataInitializer.CreateDefaultConfig(application.Key, service.Key, envKey); await _context.Environments.AddAsync(new ServiceEnvironment { Key = envKey, Name = nameDto.Name, ServiceId = service.Id }); await _context.SaveChangesAsync(); } catch (DbUpdateException e) when((e.InnerException as SqlException)?.ErrorCode == -2146232060) { return(Json(ErrorDto.Create(ErrorCodes.EnvironmentNameAleadyBusy))); } return(Ok(new { EnvironmentKey = envKey })); }
public async Task <IActionResult> Add([FromBody] NameDto nameDto) { if (!ModelState.IsValid) { return(this.ValidationError()); } Application app = this.GetApplication(); Guid servKey = Guid.NewGuid(); try { var service = new ApplicationService { Name = nameDto.Name, Key = servKey, Environments = await _defaultDataInitializer.CreateDefaultEnvironments(app.Key, servKey), ApplicationId = app.Id }; await _context.Services.AddAsync(service); await _context.SaveChangesAsync(); } catch (DbUpdateException e) when((e.InnerException as SqlException)?.ErrorCode == -2146232060) { return(Json(ErrorDto.Create(ErrorCodes.ServiceNameAleadyBusy))); } return(Ok(new { ServiceKey = servKey })); }
static void Main(string[] args) { AutoMapperOne(); Console.WriteLine("-----------------------"); AutoMapperTwo(); Console.WriteLine("----------"); AutoMapperThree(); AutoMapperFour(); AutoMapperFive(); AutoMapperSix(); AutpMapperSevevn(); AutpMapperEight(); //1.普通转换 after操作符 类似aop Name name1 = new Name() { FirstName = "L", LastName = "jz" }; Mapper.Initialize(x => x.CreateMap <Name, NameDto>().BeforeMap((name, nameDto) => Console.WriteLine("hello world before")) .AfterMap((name, nameDto) => Console.WriteLine("hello world after"))); NameDto nameDto1 = Mapper.Map <Name, NameDto>(name1); Console.WriteLine("1"); Console.WriteLine(nameDto1.FirstName + nameDto1.LastName); Console.WriteLine(); Console.Read(); }
private static void MapBaseProperties(Names sourceDbItem, NameDto targetDto) { targetDto.Id = sourceDbItem.Id; targetDto.CreateDate = sourceDbItem.CreateDate; targetDto.CreateUser = sourceDbItem.CreateUser; targetDto.UpdateDate = sourceDbItem.UpdateDate; targetDto.UpdateUser = sourceDbItem.UpdateUser; }
public async Task <List <Employee> > EmployeesNameSearch(NameDto TextSearch) { if (TextSearch.Name == null) { return(await _dataContext.Employees.Take(10).Include(e => e.Department).ToListAsync()); } return(await _dataContext.Employees.Where(x => x.Name.Contains(TextSearch.Name)).Take(10).Include(e => e.Department).ToListAsync()); }
[Route("AddCity")]// לבדוק איך קוראים בר public IHttpActionResult AddCity([FromBody] NameDto name) { bool b = Bl.PropertyBL.AddCity(name.name); if (b == true) { return(Ok()); } return(BadRequest()); }
public async Task <IActionResult> CanRegister([FromBody] NameDto nameDto) { if (!ModelState.IsValid) { return(this.ValidationError()); } bool canAdd = await _canAddModelActionHandler.Do(nameDto.Name); return(Json(new { canRegisterApplication = canAdd })); }
public async Task <IActionResult> GetValueAsync(NameDto nameDto) { if (!ModelState.IsValid) { return(this.ValidationError()); } Application app = this.GetApplication(); ApplicationService serv = this.GetService(); ServiceEnvironment env = this.GetEnvironment(); try { return(Json(await _client.GetConfigValueAsync(app.Key, serv.Key, env.Key, nameDto.Name))); } catch (KeyVaultErrorException) { return(Json(ErrorDto.Create(ErrorCodes.ConfigNameNotFound))); } }
public void UpdateTest() { NameDto newRecord = new NameDto { Name = "TestDummyNameUpdated" }; ResponseMessage response = Service.NameServices.Update(newRecord); string expected = "TestDummyNameUpdated"; Assert.IsFalse(response.IsError); Assert.IsNotNull(response.Result); Assert.IsInstanceOfType(response.Result, typeof(NameDto)); Assert.AreNotSame(expected, ((NameDto)response.Result).Name); }
public void InsertTest() { NameDto newRecord = new NameDto { Name = "TestDummyName" }; ResponseMessage response = Service.NameServices.Insert(newRecord); long notExpected = 0L; Assert.IsFalse(response.IsError); Assert.IsNotNull(response.Result); Assert.IsInstanceOfType(response.Result, typeof(NameDto)); Assert.AreNotSame(notExpected, ((NameDto)response.Result).Id); }
public static NameDto GetById(long recordId) { NameDto result = null; using (TestDbEntities db = new TestDbEntities()) { var dbRecord = db.Names.Find(recordId); if (dbRecord != null) { result = new NameDto { Name = dbRecord.Name }; MapBaseProperties(dbRecord, result); } } return(result ?? default); }
public static NameDto FindByName(string queryName) { NameDto result = null; using (TestDbEntities db = new TestDbEntities()) { var dbRecord = db.Names.FirstOrDefault(x => x.Name.Equals(queryName)); if (dbRecord != null) { result = new NameDto { Name = dbRecord.Name }; MapBaseProperties(dbRecord, result); } } return(result ?? default); }
public async Task <IActionResult> Register([FromBody] NameDto nameDto) { if (!ModelState.IsValid) { return(this.ValidationError()); } Guid appKey = Guid.NewGuid(); try { await _context.Applications.AddAsync(new Application { Name = nameDto.Name, Key = appKey, Services = await _defaultDataInitializer.CreateDefaultServices(appKey) }); await _context.SaveChangesAsync(); } catch (DbUpdateException e) when((e.InnerException as SqlException)?.ErrorCode == -2146232060) { return(Json(ErrorDto.Create(ErrorCodes.ApplicationNameAleadyBusy))); } return(Json(new { ApplicationKey = appKey })); }
public string MixedRouteQueryStringAndJson(int groupID, int userID, string name, string criteria, [FromBody] NameDto dto) { return(string.Empty); }
public string JsonObject([FromBody] NameDto dto) { return(string.Empty); }
public static ResponseMessage Update(NameDto newRecord) { throw new NotImplementedException(); }
public IHttpActionResult AddTaskType(NameDto str) { return(Ok(Bl.TaskBL.AddTaskType(str.name))); }