コード例 #1
0
        public IQueryable<ViewModels.AreaViewModel> AreaRead()
        {
            List<AreaViewModel> ret = new List<AreaViewModel>();
            var qry = db.Area;
            foreach (Area o in qry)
            {
                AreaViewModel a = new AreaViewModel();

                a.AreaID = o.AreaID;
                a.Name = o.Name;
                a.OldAreaID = o.AreaID;
                ret.Add(a);
            }
            return ret.AsQueryable();
        }
コード例 #2
0
        public bool AreaCreate(AreaViewModel areaViewModel)
        {
            bool ret = false;
            try
            {
                Area area = new Area();
                area.AreaID = areaViewModel.AreaID;
                area.Name = areaViewModel.Name;

                db.Area.Add(area);
                db.SaveChanges();

                ret = true;
            }
            catch
            {
            }
            return ret;
        }
コード例 #3
0
        public bool AreaUpdate(AreaViewModel areaViewModel)
        {
            bool ret = false;
            try
            {

                if (areaViewModel.AreaID == areaViewModel.OldAreaID)
                {

                    Area area = db.Area.Find(areaViewModel.AreaID);

                    area.Name = areaViewModel.Name;

                    db.SaveChanges();
                    ret = true;
                }
                else
                {

                    if (AreaCreate(areaViewModel))
                    {

                        var qry = db.SubArea.Where(q => q.AreaID == areaViewModel.OldAreaID);

                        foreach (SubArea o in qry)
                        {
                            o.AreaID = areaViewModel.AreaID;
                        }

                        var qry2 = db.AreaReResponsibleClass.Where(q => q.AreaID == areaViewModel.OldAreaID);

                        foreach (AreaReResponsibleClass o in qry2)
                        {
                            o.AreaID = areaViewModel.AreaID;
                        }
                        db.SaveChanges();

                        Area area = db.Area.Find(areaViewModel.OldAreaID);
                        db.Area.Remove(area);
                        db.SaveChanges();
                        ret = true;
                    }


                }
            }
            catch (DbUpdateConcurrencyException ex)
            {
                // Update the values of the entity that failed to save from the store
                ex.Entries.Single().Reload();
            }
            catch (DbEntityValidationException ex)
            {
                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 ret;
        }
コード例 #4
0
        public bool AreaDestroy(AreaViewModel areaViewModel)
        {
            bool ret = false;
            try
            {

                Area area = db.Area.Find(areaViewModel.AreaID);
                db.Area.Remove(area);
                db.SaveChanges();
                ret = true;
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
            return ret;
        }