示例#1
0
        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 }));
        }
示例#2
0
        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 }));
        }
示例#3
0
        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();
        }
示例#4
0
 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;
 }
示例#5
0
        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());
        }
示例#6
0
        [Route("AddCity")]// לבדוק איך קוראים בר
        public IHttpActionResult AddCity([FromBody] NameDto name)
        {
            bool b = Bl.PropertyBL.AddCity(name.name);

            if (b == true)
            {
                return(Ok());
            }
            return(BadRequest());
        }
示例#7
0
        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 }));
        }
示例#8
0
        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)));
            }
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
        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 }));
        }
示例#14
0
 public string MixedRouteQueryStringAndJson(int groupID, int userID, string name, string criteria, [FromBody] NameDto dto)
 {
     return(string.Empty);
 }
示例#15
0
 public string JsonObject([FromBody] NameDto dto)
 {
     return(string.Empty);
 }
示例#16
0
 public static ResponseMessage Update(NameDto newRecord)
 {
     throw new NotImplementedException();
 }
示例#17
0
 public IHttpActionResult AddTaskType(NameDto str)
 {
     return(Ok(Bl.TaskBL.AddTaskType(str.name)));
 }