コード例 #1
0
ファイル: VEPServicesModel.cs プロジェクト: thobzabuyi/cyca
        public VEP_Services CreateService(VEP_Services model)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                VEP_Services servicesTable = new VEP_Services();

                servicesTable.CaseId = model.CaseId;
                //servicesTable.PersonId = model.clientID;
                servicesTable.ServiceTypeId = model.ServiceTypeId;
                servicesTable.ServiceNotes  = model.ServiceNotes;
                servicesTable.DateCreated   = DateTime.Now;
                servicesTable.isActive      = 1;

                dbContext.VEP_Services.Add(servicesTable);
                dbContext.SaveChanges();

                return(model);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                var Test = dbEx.Message;
                return(null);
            }
        }
コード例 #2
0
ファイル: VEPServices.cs プロジェクト: thobzabuyi/cyca
        public void CreateService(VEPServicesViewModel model)
        {
            var dbContext = new SDIIS_DatabaseEntities();

            try
            {
                VEP_Services servicesTable = new VEP_Services();

                servicesTable.CaseId    = model.Caseid;
                servicesTable.ServiceId = model.Serviceid;
                //servicesTable.PersonId = model.clientID;
                servicesTable.ServiceTypeId = model.ServiceTypeid;
                servicesTable.ServiceNotes  = model.ServiceNotes.Trim();
                servicesTable.DateCreated   = DateTime.Now;
                //Value 1 means record is not active(Not deleted)
                servicesTable.isActive = 1;

                dbContext.VEP_Services.Add(servicesTable);
                dbContext.SaveChanges();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
            }
        }