Example #1
0
        public void CreateClass_UnderNormalConditions_ReturnsCreatedResponse()
        {
            //Arrange
            var classToCreate = new ClassDto()
            {
                ClassDescription = "This is a test class.",
                ClassId          = 5,
                ClassName        = "This is a test class name"
            };

            Mock.Arrange(() => _classService.Create(classToCreate))
            .Returns(classToCreate)
            .OccursOnce();

            _classController.Request.RequestUri = new Uri("http://localhost/api/class/create");

            //Act

            var actual        = _classController.Post(classToCreate) as CreatedNegotiatedContentResult <ClassDto>;
            var actualContent = actual.Content;

            //var actualContent = actual.Content;

            //Assert
            Mock.Assert(_classService);
            Assert.That(actual, Is.TypeOf <CreatedNegotiatedContentResult <ClassDto> >());
            Assert.That(actualContent, Is.EqualTo(classToCreate));
        }
Example #2
0
        static Guid CreateClass(Guid courseGuid, Guid programGuid)
        {
            ServiceFactory factory  = new ServiceFactory();
            IClassService  cService = factory.CreateClassService();

            var _class = new Class();

            // the following are required fields.
            _class.Name        = "This is test class";
            _class.CourseGuid  = courseGuid;
            _class.ProgramGuid = programGuid;

            // the following are optional fields.
            _class.StartDate = null;
            _class.EndDate   = null;

            Guid classGuid = cService.Create(_class);

            if (classGuid == Guid.Empty)
            {
                printError(cService.LastError);
            }
            else
            {
                Console.WriteLine(string.Format("Class {0} was created.", _class.Name));
            }
            return(classGuid);
        }
Example #3
0
        public async Task <IActionResult> Create(ClassInsertViewModel viewModel)
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <ClassInsertViewModel, Class>();
            });

            IMapper mapper = configuration.CreateMapper();
            Class   dto    = mapper.Map <Class>(viewModel);

            try
            {
                await _classService.Create(dto);

                return(RedirectToAction("Index", "Class"));
            }
            catch (RPGException ex)
            {
                ViewBag.ValidationErrors = ex.Errors;
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
            }
            return(View());
        }
Example #4
0
        public IActionResult Post(ClassVM classVM)
        {
            var data = _classService.Create(classVM);

            if (data > 0)
            {
                return(Ok(data));
            }
            return(BadRequest("Failed"));
            //var status = Ok(data);
        }
        public async Task <object> Post(CreateClass request)
        {
            var response = new BaseResponse();
            var entity   = request.ConvertTo <Class>();
            var result   = await _classService.Create(entity);

            response.Success    = true;
            response.StatusCode = (int)HttpStatusCode.Created;
            response.Message    = "Create class success";
            response.Results    = result;
            return(response);
        }
Example #6
0
 public IHttpActionResult Post(ClassDto classToCreate)
 {
     using (_classService)
     {
         var response = _classService.Create(classToCreate);
         if (response != null)
         {
             return(Created(new Uri(Request.RequestUri, $"{response.ClassId}"), response));
         }
         return(InternalServerError());
     }
 }
Example #7
0
 public IActionResult Create([FromBody] Class classe)
 {
     try
     {
         var response = _classService.Create(classe);
         return(Created(classe.Id, response));
     }
     catch (Exception e)
     {
         _logExceptionService.LogException(e);
         return(BadRequest(e.Message));
     }
 }
        public async Task <IActionResult> Create([FromBody] ClassRequestModel requestModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var user = _mapper.Map <Class>(requestModel);

            if (!(await _classService.Create(user)))
            {
                return(StatusCode(500));
            }
            return(StatusCode(201));
        }
        public async Task <IActionResult> Create([FromServices] IClassService classService, ClassRequest request)
        {
            if (string.IsNullOrEmpty(request.Name))
            {
                throw new ArgumentNullException(nameof(request.Name));
            }

            if (request.SchoolId == null)
            {
                throw new ArgumentNullException(nameof(request.SchoolId));
            }

            return(Ok(await classService.Create(request)));
        }
        public async Task <IActionResult> Create([FromForm] UploadClass data)
        {
            IEnumerable <IFormFile> files = data.myFiles;

            foreach (var file in files)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    await file.CopyToAsync(ms);

                    byte[] bytes = ms.ToArray();
                    ClassService.Create(bytes);
                }
            }
            return(Ok());
        }
Example #11
0
        public IActionResult Post([FromBody] ClassViewModel model)
        {
            try
            {
                classService.Create(model);

                return(Accepted());
            }
            // TODO : tratamento de exceptions
            //catch (ValidationException e)
            //{
            //    return BadRequest(new JsonErrorResponse(e.Errors));
            //}
            catch
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
Example #12
0
        public async Task <object> Create(ClassViewModel model)
        {
            Class Class = new SimpleAutoMapper <Class>().Map(model);

            try
            {
                if (await this.CheckPermissionToCreateOrUpdateClass(Class))
                {
                    Response response = await _classService.Create(Class);

                    return(response);
                }

                return(Forbid());
            }
            catch (Exception e)
            {
                Response.StatusCode = StatusCode(500).StatusCode;
                return(null);
            }
        }
        public async Task <ActionResult> Create(ClassViewModel classViewModel)
        {
            var existingCode = await _classService.FindByCode(classViewModel.ClassCode);

            if (existingCode == null)
            {
                var @class = new CreateClassDto
                {
                    ClassCode = classViewModel.ClassCode,
                    ClassName = classViewModel.ClassName,
                    Careers   = classViewModel.Careers
                };

                await _classService.Create(@class);

                return(Ok());
            }
            else
            {
                return(BadRequest("Ya existe una clase con este codigo"));
            }
        }
        public IActionResult Create([FromBody] ClassDto classDto)
        {
            // map dto to entity
            var @class = _mapper.Map <Class>(classDto);

            try
            {
                // save
                Log.Information($"Attempting to save class: {@class.Subject} from user: {@class.UserId}");
                var newClass    = _classService.Create(@class);
                var newclassDto = _mapper.Map <ClassDto>(newClass);
                newclassDto.IsOwner = true;

                return(Ok(newclassDto));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                Log.Error($"Failed to save Class");
                Log.Error(ex.StackTrace.ToString());
                return(BadRequest(new { message = ex.Message }));
            }
        }
Example #15
0
 public IHttpActionResult Create(DTOClass dtoClass)
 {
     _classService.Create(dtoClass);
     return(Ok());
 }