示例#1
0
 public void Remove(QualGroup qualGroup)
 {
     //  var QualifList = context.Qualifications.Where(q => q.QualGroupId == qualGroup.Id).ToList();
     //  if(QualifList.Count()>=0)
     //  {
     //      foreach (var item in QualifList)
     //      {
     //          if (Context.Entry(item).State == EntityState.Detached)
     //          {
     //              context.Qualifications.Attach(item);
     //          }
     //          context.Qualifications.Remove(item);
     //      }
     //  }
     //if (Context.Entry(qualGroup).State == EntityState.Detached)
     // {
     //   context.QualGroups.Attach(qualGroup);
     // }
     //context.QualGroups.Remove(qualGroup);
     if (Context.Entry(qualGroup).State == EntityState.Detached)
     {
         context.QualGroups.Attach(qualGroup);
     }
     context.QualGroups.Remove(qualGroup);
 }
示例#2
0
 public DbEntityEntry <QualGroup> Entry(QualGroup qualGroup)
 {
     return(Context.Entry(qualGroup));
 }
示例#3
0
 public void Add(QualGroup qualGroup)
 {
     context.QualGroups.Add(qualGroup);
 }
示例#4
0
 public void Attach(QualGroup qualGroup)
 {
     context.QualGroups.Attach(qualGroup);
 }
        public ActionResult CreateQualGroup(IEnumerable <QualGroupsViewModel> models, OptionsViewModel moreInfo)
        {
            var result     = new List <QualGroup>();
            var datasource = new DataSource <QualGroupsViewModel>();

            datasource.Data  = models;
            datasource.Total = models.Count();
            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    var errors = _hrUnitOfWork.CompanyRepository.Check(new CheckParm
                    {
                        CompanyId  = CompanyId,
                        ObjectName = "QualGroups",
                        Columns    = Models.Utils.GetModifiedRows(ModelState),
                        Culture    = Language
                    });

                    if (errors.Count() > 0)
                    {
                        datasource.Errors = errors;
                        return(Json(datasource));
                    }
                }
                var sequence = _hrUnitOfWork.Repository <QualGroup>().Select(a => a.Code).DefaultIfEmpty(0).Max();
                var MaxCode  = sequence == 0 ? 1 : sequence + 1;

                foreach (QualGroupsViewModel model in models)
                {
                    var qualGroup = new QualGroup();
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = qualGroup,
                        Source      = model,
                        ObjectName  = "QualGroups",
                        Transtype   = TransType.Insert,
                        Options     = moreInfo
                    });
                    qualGroup.Code = MaxCode++;
                    result.Add(qualGroup);

                    _hrUnitOfWork.QualificationRepository.Add(qualGroup);
                }

                datasource.Errors = SaveChanges(Language);
            }
            else
            {
                datasource.Errors = Models.Utils.ParseErrors(ModelState.Values);
            }


            datasource.Data = (from m in models
                               join r in result on m.Name equals r.Name into g
                               from r in g.DefaultIfEmpty()
                               select new QualGroupsViewModel
            {
                Id = (r == null ? 0 : r.Id),
                Name = m.Name,
                Code = r.Code,
                CreatedTime = DateTime.Now,
                CreatedUser = UserName,
            }).ToList();

            if (datasource.Errors.Count() > 0)
            {
                return(Json(datasource));
            }
            else
            {
                return(Json(datasource.Data));
            }
        }