Ejemplo n.º 1
0
        public int Save(ReportVM report)
        {
            var _rep = (from rep in Context.Reports
                        where rep.ThemeID == report.ThemeID &&
                        string.IsNullOrEmpty(report.ReportEnName) || rep.ReportEnName == report.ReportEnName &&
                        string.IsNullOrEmpty(report.ReportArName) || rep.ReportArName == report.ReportArName &&
                        string.IsNullOrEmpty(report.ReportFrName) || rep.ReportFrName == report.ReportFrName &&
                        rep.ReportID != report.ReportID

                        select rep).FirstOrDefault();

            if (_rep != null)
            {
                return(0);
            }
            if (report.ReportID > 0)
            {
                _rep = (from th in Context.Reports
                        where th.ThemeID == report.ThemeID && th.ReportID == report.ReportID

                        select th).FirstOrDefault();
                _rep.ReportEnName = report.ReportEnName;
                _rep.ReportArName = report.ReportArName;
                _rep.ReportFrName = report.ReportFrName;
                _rep.Source       = report.Source;
                _rep.SourceAr     = report.SourceAr;
                _rep.SourceFr     = report.SourceFr;
                _rep.PublishYear  = report.PublishYear;
                _rep.ThemeID      = report.ThemeID;
                _rep.YearTo       = report.YearTo;
                Context.Reports.Attach(_rep);

                Context.Entry(_rep).State = EntityState.Modified;
            }
            else
            {
                Report repor = new Report
                {
                    ReportID     = report.ReportID,
                    ReportEnName = report.ReportEnName,
                    ReportArName = report.ReportArName,
                    ReportFrName = report.ReportFrName,
                    Source       = report.Source,
                    SourceAr     = report.SourceAr,
                    SourceFr     = report.SourceFr,

                    ThemeID            = report.ThemeID,
                    RunningVariableID  = report.RunningVariableID,
                    changingVariableID = report.changingVariableID,
                    YearTo             = report.YearTo
                };
                Context.Reports.Add(repor);
            }

            int affectedRows = Context.SaveChanges();

            return(affectedRows);
        }
Ejemplo n.º 2
0
        public int Update(SubCodeVm subCode)
        {
            int affectedRows = 0;
            var _subCode     = (from sc in _context.SubCodes
                                where  sc.SubID == subCode.SubID && sc.LanguageID == subCode.LanguageID

                                select sc).FirstOrDefault();

            if (_subCode == null)
            {
                var item = new SubCode()
                {
                    GeneralID       = subCode.SubID.Substring(0, 3),
                    LanguageID      = subCode.LanguageID,
                    Name            = subCode.Name,
                    SubID           = subCode.SubID,
                    ParentSubCodeID = subCode.ParentSubCodeID
                };
                affectedRows = _context.SubCodes.Where(s => s.Name == item.Name && s.LanguageID == item.LanguageID && s.GeneralID == item.GeneralID).Count();
                if (affectedRows == 0)
                {
                    _context.SubCodes.Add(item);
                    _context.Entry(item).State = EntityState.Added;
                }
            }
            else
            {
                _subCode.Name = subCode.Name;
                affectedRows  = _context.SubCodes.Where(s => s.Name == _subCode.Name && s.LanguageID == _subCode.LanguageID && s.GeneralID == _subCode.GeneralID && s.SubID != _subCode.SubID).Count();
                if (affectedRows == 0)
                {
                    _context.SubCodes.Attach(_subCode);
                    _context.Entry(_subCode).State = EntityState.Modified;
                }
            }
            if (affectedRows == 0)
            {
                affectedRows = _context.SaveChanges();
            }
            else
            {
                affectedRows = 0;
            }
            return(affectedRows);
        }
Ejemplo n.º 3
0
        public int Insert(PartnerVM partener)
        {
            var partnerUpdate = Context.Partners.Where(p => p.PortalUserID == partener.PortalUserID).FirstOrDefault();

            if (partnerUpdate == null)
            {
                var _Partner = new Partner
                {
                    CEOEmail              = partener.CEOEmail,
                    PortalUserID          = partener.PortalUserID,
                    YearFounded           = partener.YearFounded,
                    PostDate              = DateTime.Now,
                    OrganizationContactID = partener.OrganizationContactID,
                    PostUserID            = partener.PostUserID,
                    Is_Approved           = 1
                };
                var _PartnersDetails = new PartnersDetail
                {
                    PartnerID    = partener.PartnerID,
                    LanguageID   = partener.LanguageID,
                    CEOFirstName = partener.CEOFirstName,
                    CEOLastName  = partener.CEOLastName,
                    GeneralDescriptionCoreBusiness = partener.GeneralDescriptionCoreBusiness,
                    PossibleAreaOfCooperation      = partener.PossibleAreaOfCooperation
                };

                _Partner.PartnersDetails.Add(_PartnersDetails);
                Context.Partners.Add(_Partner);
            }
            else
            {
                partnerUpdate.Is_Approved           = 1;
                partnerUpdate.CEOEmail              = partener.CEOEmail;
                partnerUpdate.UpdateUserID          = partener.UpdateUserID;
                partnerUpdate.YearFounded           = partener.YearFounded;
                partnerUpdate.UpdateDate            = DateTime.Now;
                partnerUpdate.OrganizationContactID = partener.OrganizationContactID;
                Context.Partners.Attach(partnerUpdate);
                Context.Entry(partnerUpdate).State = EntityState.Modified;
                var partnerUpdatedet = Context.PartnersDetails.Where(p => p.PartnerID == partnerUpdate.PartnerID && p.LanguageID == partener.LanguageID).FirstOrDefault();
                if (partnerUpdatedet != null)
                {
                    partnerUpdatedet.CEOFirstName = partener.CEOFirstName;
                    partnerUpdatedet.CEOLastName  = partener.CEOLastName;
                    partnerUpdatedet.LanguageID   = partener.LanguageID;
                    partnerUpdatedet.GeneralDescriptionCoreBusiness = partener.GeneralDescriptionCoreBusiness;
                    partnerUpdatedet.PossibleAreaOfCooperation      = partener.PossibleAreaOfCooperation;
                    Context.PartnersDetails.Attach(partnerUpdatedet);
                    Context.Entry(partnerUpdatedet).State = EntityState.Modified;
                }
                else
                {
                    var _PartnersDetails = new PartnersDetail
                    {
                        PartnerID    = partnerUpdate.PartnerID,
                        LanguageID   = partener.LanguageID,
                        CEOFirstName = partener.CEOFirstName,
                        CEOLastName  = partener.CEOLastName,
                        GeneralDescriptionCoreBusiness = partener.GeneralDescriptionCoreBusiness,
                        PossibleAreaOfCooperation      = partener.PossibleAreaOfCooperation
                    };
                    Context.PartnersDetails.Add(_PartnersDetails);
                }
            }

            return(Context.SaveChanges());
        }
Ejemplo n.º 4
0
        public IndividualVM UpdatePersonalInfo(IndividualVM vm)
        {
            var dbContext = new LMISEntities();

            try
            {
                var individualObject = dbContext.IndividualDetails.Single(i => i.PortalUsersID == vm.PortalUsersID);

                #region 1st: Update portal user

                individualObject.PortalUser.IDNumber = vm.PortalUser.IDNumber;
                individualObject.PortalUser.IDType   = vm.PortalUser.IDType;
                if (individualObject.Email != vm.Email)
                {
                    var user = dbContext.AspNetUsers.Where(u => u.Id == vm.UserID).SingleOrDefault();
                    user.UserName = vm.Email;
                    user.Email    = vm.Email;
                    dbContext.Entry(user).State = EntityState.Modified;
                }

                #endregion

                #region 2nd: Populate Individual object

                individualObject.MobileNo          = vm.MobileNo;
                individualObject.TelephoneNo       = vm.TelephoneNo;
                individualObject.DateOfBirth       = vm.DateOfBirth;
                individualObject.Email             = vm.Email;
                individualObject.MaritalStatusId   = vm.MaritalStatusId;
                individualObject.GenderId          = vm.GenderId;
                individualObject.MilitaryStatus_Id = vm.GenderId == "00200002" ? vm.MilitaryStatus_Id : string.Empty;
                individualObject.NationalityId     = string.IsNullOrEmpty(vm.NationalityId)
                    ? individualObject.NationalityId
                    : vm.NationalityId;
                individualObject.CountryID           = vm.CountryID;
                individualObject.CityID              = vm.CityID;
                individualObject.IndividualMedicalID = vm.IndividualMedicalID;
                individualObject.AllowtoViewMyInfo   = vm.AllowtoViewMyInfo;
                individualObject.UpdateDate          = System.DateTime.Now;
                individualObject.UpdateUserID        = individualObject.AspNetUser.Id;
                individualObject.PhotoPath           = string.IsNullOrEmpty(vm.PhotoPath)
                    ? individualObject.PhotoPath
                    : vm.PhotoPath;
                individualObject.Is_Approved = (int)Approval.Pending;

                #endregion

                #region 3rd: Delete details

                var dr = individualObject.IndividualDetailsDets
                         .Where(r => r.PortalUsersID == vm.PortalUsersID)
                         .ToList();

                dbContext.IndividualDetailsDets.RemoveRange(dr);

                #endregion

                #region 4th: Add translations

                foreach (
                    IndividualTranslationVM translation in
                    vm.Translation.Where(t => t.FirstName != null || t.LastName != null || t.Address != null))
                {
                    IndividualDetailsDet translationObject = new IndividualDetailsDet
                    {
                        PortalUsersID = individualObject.PortalUsersID,
                        LanguageID    = translation.LanguageID,
                        FirstName     = translation.FirstName,
                        LastName      = translation.LastName,
                        Address       = translation.Address
                    };
                    individualObject.IndividualDetailsDets.Add(translationObject);
                }

                #endregion

                #region 5th: Save Individual object

                dbContext.Entry(individualObject).State = EntityState.Modified;

                dbContext.SaveChanges();

                #endregion

                return(vm);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:");
                }
                throw;
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        public void Update(ref OrganizationVM vm, string userId)
        {
            var dbContext = new LMISEntities();

            var portalUserId = vm.PortalUsersID;

            #region 1st: Update portal user

            var portalUser = dbContext.PortalUsers.Single(pu => pu.PortalUsersID == portalUserId);

            // portalUser.PortalUsersID = organizationVM.PortalUser.PortalUsersID;
            portalUser.IDType           = vm.PortalUser.IDType;
            portalUser.IDNumber         = vm.PortalUser.IDNumber;
            portalUser.UserCategory     = vm.PortalUser.UserCategory;
            portalUser.UserSubCategory  = vm.PortalUser.UserSubCategory;
            portalUser.TrainingProvider = vm.PortalUser.TrainingProvider;
            portalUser.Employer         = vm.PortalUser.Employer;
            portalUser.JobSeeker        = vm.PortalUser.JobSeeker;
            portalUser.TrainingSeeker   = vm.PortalUser.TrainingSeeker;
            portalUser.Researcher       = vm.PortalUser.Researcher;
            portalUser.Internal         = vm.PortalUser.Internal;
            portalUser.IsSubscriper     = vm.PortalUser.IsSubscriper;

            dbContext.Entry(portalUser).State = EntityState.Modified;
            dbContext.SaveChanges();

            #endregion

            using (var transaction = dbContext.Database.BeginTransaction())
            {
                #region 3rd: Populate Organization object

                var organizationObject = dbContext.OrganizationDetails.Single(org => org.PortalUsersID == portalUserId);
                PopulateRecord(ref organizationObject, vm, vm.PortalUsersID);
                organizationObject.UpdateDate   = DateTime.UtcNow;
                organizationObject.UpdateUserID = userId;

                #endregion

                #region remove old translations
                var details = dbContext.OrganizationDetails_Det
                              .Where(r => r.PortalUsersID == portalUserId)
                              .ToList();
                foreach (var row in details)
                {
                    organizationObject.OrganizationDetails_Det.Remove(row);
                }

                dbContext.OrganizationDetails_Det.RemoveRange(details);
                //dbContext.SaveChanges();
                #endregion

                #region 4th: Add translations
                foreach (var translation in vm.Translation.Where(t => t.OrganizationName != null || t.Address != null || t.OtherIndustryType != null))
                {
                    var translationObject = new OrganizationDetails_Det
                    {
                        PortalUsersID     = portalUser.PortalUsersID,
                        LanguageID        = translation.LanguageID,
                        OrganizationName  = translation.OrganizationName,
                        Address           = translation.Address,
                        OtherIndustryType = translation.OtherIndustryType
                    };
                    organizationObject.OrganizationDetails_Det.Add(translationObject);
                }
                #endregion

                #region 6th: Save Organization object
                organizationObject.UpdateUserID = userId;
                organizationObject.UpdateDate   = DateTime.UtcNow;

                dbContext.Entry(organizationObject).State = EntityState.Modified;
                dbContext.SaveChanges();
                transaction.Commit();
                #endregion
            }
        }
Ejemplo n.º 6
0
        public int Save(ThemeVm theme)

        {
            theme.Name = !string.IsNullOrEmpty(theme.Name)
                ? theme.Name
                : string.IsNullOrEmpty(theme.NameAr) ? theme.NameAr : theme.NameFr;
            theme.NameAr = !string.IsNullOrEmpty(theme.NameAr)
                ? theme.NameAr
                : !string.IsNullOrEmpty(theme.Name) ? theme.Name : theme.NameFr;
            theme.NameFr = !string.IsNullOrEmpty(theme.NameFr)
                ? theme.NameFr
                : !string.IsNullOrEmpty(theme.Name) ? theme.Name : theme.NameAr;
            theme.ThemeType = theme.ThemeType;
            theme.UnitScale = !string.IsNullOrEmpty(theme.UnitScale)
                ? theme.UnitScale
                : !string.IsNullOrEmpty(theme.UnitScaleAr) ? theme.UnitScaleAr : theme.UnitScaleFr;
            theme.UnitScaleAr = !string.IsNullOrEmpty(theme.UnitScaleAr)
                ? theme.UnitScaleAr
                : !string.IsNullOrEmpty(theme.UnitScale) ? theme.UnitScale : theme.UnitScaleFr;
            theme.UnitScaleFr = !string.IsNullOrEmpty(theme.UnitScaleFr)
                ? theme.UnitScaleFr
                : !string.IsNullOrEmpty(theme.UnitScale) ? theme.UnitScale : theme.UnitScaleAr;


            DimTheme them = new DimTheme
            {
                CodeNo      = theme.CodeNo,
                Name        = theme.Name,
                NameAr      = theme.NameAr,
                NameFr      = theme.NameFr,
                ThemeType   = theme.ThemeType,
                UnitScale   = theme.UnitScale,
                UnitScaleAr = theme.UnitScaleAr,
                UnitScaleFr = theme.UnitScaleFr
            };
            var _them = (from th in Context.DimThemes where th.Name == theme.Name && th.NameAr == theme.NameAr && th.NameFr == theme.NameFr && (th.CodeNo != theme.CodeNo || theme.CodeNo == 0) select th).FirstOrDefault();

            if (_them != null)
            {
                return(-4);
            }
            if (theme.CodeNo > 0)
            {
                _them             = (from th in Context.DimThemes where  th.CodeNo == theme.CodeNo select th).FirstOrDefault();
                _them.Name        = theme.Name;
                _them.NameAr      = theme.NameAr;
                _them.NameFr      = theme.NameFr;
                _them.UnitScale   = theme.UnitScale;
                _them.UnitScaleAr = theme.UnitScaleAr;
                _them.UnitScaleFr = theme.UnitScaleFr;
                _them.ThemeType   = theme.ThemeType;
                Context.DimThemes.Attach(_them);
                Context.Entry(_them).State = EntityState.Modified;
            }
            else
            {
                Context.DimThemes.Add(them);
            }
            int affectedRows = Context.SaveChanges();

            return(affectedRows);
        }
Ejemplo n.º 7
0
        public int Insert(Infrastructure.Data.Entities.NewsVm news)
        {
            try
            {
                News _news = new News
                {
                    NewsTitle       = news.NewsTitle,
                    NewsDescription = news.NewsDescription,
                    NewsDate        = news.NewsDate,
                    NewsExpiryDate  = news.NewsExpiryDate,
                    NewsBannerPath  = news.NewsBannerPath,
                    NewsIconPath    = news.NewsIconPath,
                    NewsVideoPath   = news.NewsVideoPath,
                    NewsLangauage   = news.NewsLangauage,
                    PostUserID      = news.PostUserID,
                    PostDate        = DateTime.Now,
                    IsInformal      = news.IsInformal,
                    IsAchievement   = news.IsAchievement
                };
                int affectedRows = 0;
                using (var db = new LMISEntities())
                {
                    if (news.NewsID < 1)
                    {
                        db.News.Add(_news);
                    }
                    else
                    {
                        var _News = (from n in db.News where n.NewsID == news.NewsID select n).FirstOrDefault();
                        _News.NewsTitle       = news.NewsTitle;
                        _News.NewsDescription = news.NewsDescription;
                        _News.NewsDate        = news.NewsDate;
                        _News.NewsExpiryDate  = news.NewsExpiryDate;
                        _News.IsInformal      = news.IsInformal;
                        _News.IsAchievement   = news.IsAchievement;
                        if (!string.IsNullOrEmpty(news.NewsBannerPath))
                        {
                            _News.NewsBannerPath = news.NewsBannerPath;
                        }
                        if (!string.IsNullOrEmpty(news.NewsIconPath))
                        {
                            _News.NewsIconPath = news.NewsIconPath;
                        }
                        if (!string.IsNullOrEmpty(news.NewsVideoPath))
                        {
                            _News.NewsVideoPath = news.NewsVideoPath;
                        }
                        db.News.Attach(_News);
                        db.Entry(_News).State = EntityState.Modified;
                    }

                    db.SaveChanges();

                    affectedRows = int.Parse(_news.NewsID.ToString());
                }
                return(affectedRows);
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            catch (DbUnexpectedValidationException ex)
            {
                Console.WriteLine(ex.StackTrace + ":" + ex.InnerException);
                throw;
            }
        }
        public int Insert(ReportVM fixedVariables, int themeId, string changingVariable, string runningVariable, string changingValue, string runningValue, decimal value)
        {
            string changingVariableColumn = "";
            string runningVariableColumn  = "";

            changingVariableColumn = Utils.VariableName(changingVariable.Substring(0, 3));
            if (!string.IsNullOrEmpty(runningVariable))
            {
                runningVariableColumn = Utils.VariableName(runningVariable.Substring(0, 3));
            }


            FactStatisticalData item = new FactStatisticalData();

            if (fixedVariables != null)
            {
                item.YearID = fixedVariables.YearID;
                foreach (var column in fixedVariables.GetType().GetProperties())
                {
                    if (
                        !"ReportID,ThemeNameAr,ThemeNameFr,UnitScaleAr,UnitScaleFr,ReportEnName,ReportArName,ReportFrName,ThemeID,ThemeName,ThemeType,UnitScale,RunningVariableID,changingVariableID,RunningVariableName,changingVariableName,FixedVariable,YearTo,Source,SourceAr,SourceFr,PublishYear"
                        .Contains(column.Name))
                    {
                        item.GetType().GetProperty(column.Name).SetValue(item, column.GetValue(fixedVariables, null));
                    }
                }
            }



            // item.SectorID = fixedVariables.SectorID;
            //  item.AgeID = fixedVariables.AgeID;
            item.GetType().GetProperty(changingVariableColumn).SetValue(item, changingValue.Substring(0, 8));
            if (!string.IsNullOrEmpty(runningVariable))
            {
                item.GetType().GetProperty(runningVariableColumn).SetValue(item, runningValue.Substring(0, 8));
            }
            item.ThemeID = themeId;
            item.Value   = value;

            if (_context.FactStatisticalDatas.Where(r =>
                                                    (item.AgeID == null || r.AgeID == item.AgeID) &&
                                                    (item.EducationLevelID == null || r.EducationLevelID == item.EducationLevelID) &&
                                                    (item.AgeID == null || r.AgeID == item.AgeID) &&
                                                    (item.GenderID == null || r.GenderID == item.GenderID) &&
                                                    (item.GovID == null || r.GovID == item.GovID) &&
                                                    (item.MaritalStatusID == null || r.MaritalStatusID == item.MaritalStatusID) &&
                                                    (item.YearID == null || r.YearID == item.YearID) &&
                                                    (item.FactDataID == null || r.FactDataID == item.FactDataID) &&
                                                    (item.ThemeID == null || r.ThemeID == item.ThemeID)

                                                    ).Any() == false)
            {
                _context.FactStatisticalDatas.Add(item);
            }
            else
            {
                _context.FactStatisticalDatas.Attach(item);
                _context.Entry(item).State = EntityState.Modified;
            }
            return(_context.SaveChanges());
        }