示例#1
0
        private int GetProjectCostPlan(string projRef, long newId)
        {
            var proReference = new ProjectCostPlan()
            {
                created_at  = DateTime.Now,
                modified_at = DateTime.Now,
                details     = projRef,
                proj_id     = (int)newId
            };

            _insendluEntities.ProjectCostPlans.Add(proReference);

            try
            {
                _insendluEntities.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }

            return((int)proReference.id);
        }
示例#2
0
        private void UpdateCostPlan(string costP, ProjectCostPlan plan, DateTime date)
        {
            plan.details     = costP;
            plan.modified_at = date;

            _insendluEntities.Entry(plan).State = System.Data.Entity.EntityState.Modified;
            _insendluEntities.SaveChanges();
        }
示例#3
0
        private int GetProjectCostPlan(string projRef, long newId)
        {
            var proReference = new ProjectCostPlan
            {
                created_at  = DateTime.Now,
                modified_at = DateTime.Now,
                deliverable = projRef,
                proj_id     = (int)newId
            };

            _insendluEntities.ProjectCostPlans.Add(proReference);

            TryCatch();

            return((int)proReference.id);
        }