Esempio n. 1
0
        public ActionResult <SingleRecordDto> CreateRecord([FromBody, Required] RecordForCreationDto record)
        {
            try
            {
                var recordEntity = _mapper.Map <Record>(record);

                if (!_recordsRepository.EmployeeExists(recordEntity.EmployeeId))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden));
                }

                if (_recordsRepository.RecordExists(recordEntity.Id))
                {
                    return(StatusCode(StatusCodes.Status403Forbidden));
                }

                _recordsRepository.AddRecord(recordEntity);

                var recordToReturn = _mapper.Map <SingleRecordDto>(recordEntity);
                return(CreatedAtRoute("GetRecordv2",
                                      new
                {
                    recordId = recordToReturn.Id
                },
                                      recordToReturn));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 2
0
        public bool AddFromString(string data)
        {
            if (string.IsNullOrWhiteSpace(data))
            {
                throw new ArgumentNullException("data");
            }


            var           parser = new DelimitedFileParser(data, true);
            List <Person> people = parser.GetRecords <Person>(_stringsToPerson);

            foreach (var person in people)
            {
                _recordsRepository.AddRecord(person);
            }
            return(true);
        }
Esempio n. 3
0
 public IActionResult AddRecord(Record record)
 {
     if (ModelState.IsValid)
     {
         TopRecordsList = _topRecordsRepository.AddRecord(record);
         Thread.Sleep(5000);
         return(RedirectToAction("Index", "Home"));
     }
     foreach (var modelState in ViewData.ModelState.Values)
     {
         foreach (var error in modelState.Errors)
         {
             ModelState.AddModelError(string.Empty, error.ErrorMessage);
         }
     }
     return(View());
 }