public Domain.Observation Add(
            IValidationDictionary validationDictionary,
            Domain.Observation observation,
            HttpPostedFileBase postedFile)
        {
            if (!Validate(validationDictionary, observation))
            {
                return(null);
            }

            SetObservationValues(observation);

            var data = _observationRepository.Create();

            _observationRepository.Add(data);

            Mapper.Map(observation, data);

            //Reset the observation ID so that consumers cannot set this.
            data.ObservationId = 0;

            SaveFile(data, postedFile);
            _context.SaveChanges();

            //Map back to the domain so we can use the full
            //result in the web site for sending email, etc.

            return(Mapper.Map <Domain.Observation>(data));
        }
Пример #2
0
        public IActionResult Post([FromBody] Observation observation)
        {
            observation.Id           = Guid.NewGuid();
            observation.DateCreated  = DateTime.UtcNow;
            observation.DateModified = DateTime.UtcNow;
            var data  = dbContext.Observations.ToList();
            var count = data.Count() != 0 ? data.Max(a => a.RefNo) : 0;

            observation.RefNo = count + 1;
            try
            {
                dbContext.Observations.Add(observation);
                dbContext.SaveChanges();
                _ = SendMail(observation, true);
                return(new OkObjectResult(observation));
            }
            catch
            {
                return(BadRequest("Something went wrong, Details not added"));
            }
        }
 public void SaveChanges()
 {
     _context.SaveChanges();
 }