Exemplo n.º 1
0
        public ContentResult editschool(SchoolRequest request)
        {
            var msg  = string.Empty;
            var flag = _schoolService.Edit(request, UserContext.SysUserContext.Id, out msg);

            return(Result <string>(flag, msg));
        }
Exemplo n.º 2
0
        public async Task <SchoolResponse> Create(SchoolRequest request)
        {
            try
            {
                var _scholl = await _context.Schools.AddAsync(new School
                {
                    Name    = request.Name,
                    Address = request.Address
                });

                await _context.SaveChangesAsync();

                return(new SchoolResponse
                {
                    Id = _scholl.Entity.Id,
                    Name = _scholl.Entity.Name,
                    Address = _scholl.Entity.Address,
                    CreatedDate = _scholl.Entity.CreatedDate
                });
            }
            catch (Exception ex)
            {
                throw new DatabaseException(ex.Message);
            }
        }
Exemplo n.º 3
0
 internal static School ConvertRequestToSchool(SchoolRequest schoolRequest)
 {
     return(new School
     {
         Name = schoolRequest.Name
     });
 }
Exemplo n.º 4
0
        // 编辑学校
        public bool Edit(SchoolRequest request, int sysUserId, out string msg)
        {
            bool flag = false;

            msg = string.Empty;
            try
            {
                if (request.ProvinceId <= 0)
                {
                    msg = "省份不能为空";
                    return(flag);
                }
                if (request.CityId <= 0)
                {
                    msg = "城市不能为空";
                    return(flag);
                }

                if (request.ChinessName.IsEmpty())
                {
                    msg = "学校名称不能为空";
                    return(flag);
                }

                var school = _dbContext.Get <t_sys_school>(request.Id);
                if (school != null)
                {
                    school.provinceId  = request.ProvinceId;
                    school.englishname = request.EnglishName;
                    school.chinessname = request.ChinessName;
                    school.isInter     = request.IsInter;
                    school.cityId      = request.CityId;
                    school.updatetime  = DateTime.Now;
                    _dbContext.Update(school);
                    flag = true;
                }
                else
                {
                    msg = "学校信息不存在";
                }
            }
            catch (Exception ex)
            {
                flag = false;
                msg  = "服务异常";
                LogUtils.LogError("SchoolService.Edit", ex);
            }
            return(flag);
        }
        public async Task <IActionResult> Register(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "school")]
            [RequestBodyType(typeof(SchoolRequest), "Create/update school")] HttpRequest request)
        {
            var validateStatus = base.AuthorizationStatus(request);

            if (validateStatus != System.Net.HttpStatusCode.Accepted)
            {
                return(new BadRequestObjectResult(validateStatus));
            }

            string        requestBody = await new StreamReader(request.Body).ReadToEndAsync();
            SchoolRequest requestData = JsonConvert.DeserializeObject <SchoolRequest>(requestBody);

            await _schoolService.CreateUpdate(requestData);

            return(new OkObjectResult(new { message = "Create/update school successful." }));
        }
Exemplo n.º 6
0
        //新增学校
        public bool Insert(SchoolRequest request, int sysUserId, out string msg)
        {
            bool flag = false;

            msg = string.Empty;
            try
            {
                if (request.ProvinceId <= 0)
                {
                    msg = "省份不能为空";
                    return(flag);
                }
                if (request.CityId <= 0)
                {
                    msg = "城市不能为空";
                    return(flag);
                }

                if (request.ChinessName.IsEmpty())
                {
                    msg = "学校名称不能为空";
                    return(flag);
                }

                var model = new t_sys_school {
                    cityId      = request.CityId,
                    englishname = request.EnglishName,
                    chinessname = request.ChinessName,
                    isInter     = request.IsInter,
                    provinceId  = request.ProvinceId
                };
                _dbContext.Insert(model);
                flag = true;
            }
            catch (Exception ex)
            {
                flag = false;
                msg  = "服务异常";
                LogUtils.LogError("SchoolService.Insert", ex);
            }
            return(flag);
        }
Exemplo n.º 7
0
        public async Task <MessageResponse <SchoolRequestResponse> > InsertAsync(SchoolRequest schoolRequest)
        {
            var messageResponse = new MessageResponse <SchoolRequestResponse>();

            try
            {
                var result = await _schoolService.InsertAsync(schoolRequest);

                messageResponse.IsSuccess  = true;
                messageResponse.StatusCode = HttpStatusCode.OK;
                messageResponse.Message    = "Inserido com sucesso";
                messageResponse.Count      = result;
            }
            catch (Exception e)
            {
                messageResponse.IsSuccess = false;
                messageResponse.Message   = e.Message.ToString();
            }

            return(messageResponse);
        }
        public Task <IActionResult> Add([FromBody] SchoolRequest schoolRequest)
        {
            var result = _schoolAppService.InsertAsync(schoolRequest).Result;

            return(Response(result.StatusCode, result));
        }
        public async Task <IActionResult> Create([FromServices] ISchoolService schoolService, SchoolRequest request)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                throw new ArgumentNullException(nameof(request.Name));
            }

            if (string.IsNullOrEmpty(request.Address))
            {
                throw new ArgumentNullException(nameof(request.Address));
            }

            return(Ok(await schoolService.Create(request)));
        }
Exemplo n.º 10
0
        /// <summary>
        /// The CreateUpdate.
        /// </summary>
        /// <param name="model">The model<see cref="SchoolRequest"/>.</param>
        /// <returns>The <see cref="Task"/>.</returns>
        public async Task CreateUpdate(SchoolRequest model)
        {
            // validate
            var school = await this.GetSchool(model.Id);

            if (school != null)
            {
                school.Name      = model.Name;
                school.Address1  = model.Address1;
                school.Address2  = model.Address2;
                school.Country   = model.Country;
                school.State     = model.State;
                school.City      = model.City;
                school.Zip       = model.Zip;
                school.Latitude  = model.Latitude;
                school.Longitude = model.Longitude;
                school.CreatedBy = model.CreatedBy;
                school.UpdatedOn = DateTime.UtcNow;
                school.UpdatedBy = model.CreatedBy;
                school.ImageURL  = model.ImageURL;

                try
                {
                    await _tableStorage.UpdateAsync("School", school);
                }
                catch (Exception ex)
                {
                    throw new AppException("update school error: ", ex.InnerException);
                }
            }
            else
            {
                var schoolId  = String.IsNullOrEmpty(model.Id) ? Guid.NewGuid().ToString() : model.Id;
                var newSchool = new Entites.School(schoolId, schoolId)
                {
                    Name      = model.Name,
                    Address1  = model.Address1,
                    Address2  = model.Address2,
                    Country   = model.Country,
                    State     = model.State,
                    City      = model.City,
                    Zip       = model.Zip,
                    Latitude  = model.Latitude,
                    Longitude = model.Longitude,
                    Active    = true,
                    CreatedBy = model.CreatedBy,
                    UpdatedOn = DateTime.UtcNow,
                    UpdatedBy = model.CreatedBy,
                    ImageURL  = model.ImageURL,
                };

                try
                {
                    await _tableStorage.AddAsync("School", newSchool);
                }
                catch (Exception ex)
                {
                    throw new AppException("Create school error: ", ex.InnerException);
                }
            }
        }
        public async Task <int> InsertAsync(SchoolRequest schoolRequest)
        {
            var school = SchoolServiceMapper.ConvertRequestToSchool(schoolRequest);

            return(await _unitOfWork.SchoolRepository.AddAsync(school).ConfigureAwait(false));
        }