Пример #1
0
        public JsonResult AddPersonMeasuring(PersonMeasuring personMeasuring)
        {
            var isSuccessfully = true;
            var error = string.Empty;

                try
                {
                    this.personMeasuringRepository.CreateOrUpdateEntity(personMeasuring);
                }
                catch (Exception ex)
                {
                    isSuccessfully = false;
                    error = ex.Message;
                }

            return this.Json(new { IsSuccessfully = isSuccessfully, Error = error });
        }
Пример #2
0
        public PersonMeasuring CreateOrUpdateEntity(PersonMeasuring entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            using (var context = new TrashDomainContext(this.ConnectionString))
            {
                if (this.GetEntityById(entity.Id) == null)
                {
                    context.PersonMeasurings.Add(entity);
                }
                else
                {
                    context.Entry(entity).State = EntityState.Modified;
                }

                context.SaveChanges();
            }

            return entity;
        }