Exemple #1
0
        public void Deactivate(long id, string ntLogin)
        {
            var data = _context.AsQueryable <LoB>().Where(x => x.ID == id).FirstOrDefault();

            if (data == null)
            {
                throw new ArgumentException("Data does not exists.");
            }

            data.Active       = false;
            data.DateModified = DateTime.Now;
            data.ModifiedBy   = ntLogin;

            _context.Update <LoB>(data);
            _context.SaveChanges();
        }
        public SiteCampaignLobFormulaViewModel Update(SiteCampaignLobFormulaViewModel model)
        {
            //check if exists

            #region Validate

            var data = _context.AsQueryable <SiteCampaignLobFormula>()
                       .Where(x => x.ID == model.ID).FirstOrDefault();

            long origSiteID     = 0;
            long origCampaignID = 0;
            long origLobID      = 0;

            if (data != null)
            {
                if (data.ID > 0)
                {
                    origSiteID     = data.SiteID;
                    origCampaignID = data.CampaignID;
                    origLobID      = data.LoBID;
                }
            }

            if (origSiteID != model.SiteID && origCampaignID != model.CampaignID && origLobID != model.LoBID)
            {
                var existingdata = this.Get(model.SiteID, model.CampaignID, model.LoBID, null, true);
                if (existingdata.Count() > 0)
                {
                    throw new ArgumentException("Update failed. Mapping already exists.");
                }
            }

            #endregion Validate

            data.SiteID           = model.SiteID;
            data.CampaignID       = model.CampaignID;
            data.LoBID            = model.LoBID;
            data.DynamicFormulaID = model.DynamicFormulaID;
            data.DateModified     = DateTime.Now;

            _context.Update <SiteCampaignLobFormula>(data);
            _context.SaveChanges();

            return(model);
        }
        public void Deactivate(long campaignID)
        {
            var siteCampaings = _context.AsQueryable <SiteCampaign>().Where(x => x.CampaignID == campaignID).ToList();

            foreach (var siteCampaign in siteCampaings)
            {
                siteCampaign.Active = false;
                _context.Update <SiteCampaign>(siteCampaign);
                _context.SaveChanges();
            }
        }
        public void Update(SiteCampaignLoBViewModel model)
        {
            try
            {
                if (model != null)
                {
                    SiteCampaignLoB data = _context.AsQueryable <SiteCampaignLoB>().Where(x => x.ID == model.ID).FirstOrDefault();
                    data.SiteID     = model.SiteID;
                    data.CampaignID = model.CampaignID;
                    data.LoBID      = model.LobID;
                    data.Active     = model.Active;

                    _context.Update <SiteCampaignLoB>(data);
                    _context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Unexpected error encountered. Please contact your system administrator.", ex.InnerException);
            }
        }
        public void Save(WeeklyDatapointViewModel model)
        {
            //check data if exists
            var orig = _context.AsQueryable <WeeklyDatapoint>()
                       .Where(x => x.Date == model.Date && x.DatapointID == model.DatapointID &&
                              x.SiteID == model.SiteID && x.CampaignID == model.CampaignID && x.LoBID == model.LoBID)
                       .FirstOrDefault();

            WeeklyDatapoint data = new WeeklyDatapoint();

            if (orig != null)
            {
                orig.Data         = model.Data;
                orig.ModifiedBy   = model.ModifiedBy;
                orig.DateModified = model.DateModified;

                _context.Update <WeeklyDatapoint>(orig);
                _context.SaveChanges();
            }
            else
            {
                data = new WeeklyDatapoint()
                {
                    SiteID       = model.SiteID,
                    CampaignID   = model.CampaignID,
                    LoBID        = model.LoBID,
                    DatapointID  = model.DatapointID,
                    Week         = model.Week,
                    Data         = model.Data,
                    Date         = model.Date,
                    CreatedBy    = model.CreatedBy,
                    ModifiedBy   = null,
                    DateCreated  = model.DateCreated,
                    DateModified = null
                };

                _context.Add(data);
                _context.SaveChanges();
            }
        }