예제 #1
0
        /// <summary>
        /// Insert new localization.
        /// </summary>
        /// <param name="localization"></param>
        protected static void InsertLocalization(Canon.Data.Localization localization)
        {
            CanonDataContext db = Cdb.Instance;

            db.Localizations.InsertOnSubmit(localization);
            db.SubmitChanges();
        }
예제 #2
0
파일: User.cs 프로젝트: radtek/canon
        public static void UpdateRightsRelation(int userId, int rightId, bool relationExist)
        {
            CanonDataContext db = Cdb.Instance;

            try
            {
                UsersRight uc = db.UsersRights.First(u => u.UserId == userId && u.Rights == rightId);
                if (!relationExist)
                {
                    db.UsersRights.DeleteOnSubmit(uc);
                }
            }
            catch (Exception ex)
            {
                //there is no such relation
                if (relationExist)
                {
                    UsersRight newUc = new UsersRight();
                    newUc.Rights = rightId;
                    newUc.UserId = userId;
                    db.UsersRights.InsertOnSubmit(newUc);
                }
            }
            db.SubmitChanges();
        }
예제 #3
0
        public static void InsertImportPriceList(ImportPriceList newValue)
        {
            CanonDataContext db = Cdb.Instance;

            db.ImportPriceLists.InsertOnSubmit(newValue);
            db.SubmitChanges();
        }
예제 #4
0
        protected List <int> GetListOfChannels()
        {
            CanonDataContext db   = Cdb.Instance;
            List <int>       list = new List <int>();

            foreach (ListItem li in lstShops.Items)
            {
                if ((li.Value == "0") && (li.Selected))
                {
                    //put all ids of defined channel type
                    List <Channel> channels = db.Channels.Where(c => c.IsActive == true &&
                                                                c.ChannelType == int.Parse(rblShopTypes.SelectedItem.Value.ToString())).ToList();
                    foreach (Channel channel in channels)
                    {
                        list.Add(channel.ChannelId);
                    }
                    return(list);
                }
                else if (li.Selected)
                {
                    list.Add(int.Parse(li.Value));
                }
            }
            if (list.Count == 0)
            {
                //put all ids of defined channel type
                List <Channel> channels = db.Channels.Where(c => c.IsActive == true &&
                                                            c.ChannelType == int.Parse(rblShopTypes.SelectedItem.Value.ToString())).ToList();
                foreach (Channel channel in channels)
                {
                    list.Add(channel.ChannelId);
                }
            }
            return(list);
        }
예제 #5
0
        public static void AddToExceptions(int channelId, int productId)
        {
            CanonDataContext db   = Cdb.Instance;
            MappingRule      rule = db.MappingRules.Where(r => r.ChannelId == channelId &&
                                                          r.ProductId == productId).FirstOrDefault();

            if (rule != null)
            {
                db.MappingRules.DeleteOnSubmit(rule);
            }

            Excluded old = db.Excludeds.FirstOrDefault(d => d.ChannelId == channelId && d.ProductId == productId);

            if (old != null)
            {
                return;
            }
            Excluded exc = new Excluded();

            exc.ProductId = productId;
            exc.ChannelId = channelId;
            db.Excludeds.InsertOnSubmit(exc);
            db.SubmitChanges();
            CanonProductsLog.Add(channelId, productId, MappingLogEnum.AddedToExceptions);
        }
예제 #6
0
        /// <summary>
        /// Validate user.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public override bool ValidateUser(string username, string password)
        {
            CanonDataContext db = Cdb.Instance;

            try
            {
                List <User> users = db.Users.Where(u => u.UserName == username).ToList();

                foreach (User user in users)
                {
                    if (user.IsForbidden == true || user.IsActive == false)
                    {
                        continue;
                    }

                    if (CheckPassword(password, user.Password))
                    {
                        SessionManager.LoggedUser = user;
                        UpdateUserLastLogin(user);
                        return(true);
                    }
                }

                return(false);
            }
            catch
            {
                return(false);
            }
        }
예제 #7
0
        protected override void BindData()
        {
            CanonDataContext db = Cdb.Instance;

            gridPrices.DataSource = db.Products.Where(p => p.IsActive == true);
            gridPrices.DataBind();
        }
예제 #8
0
        public void CheckIfPriceIsChanged(int channelId, string productName, string productUrl, decimal price)
        {
            CanonDataContext db = Cdb.Instance;
            //try to find mapping rule
            MappingRule mr = db.MappingRules.Where(m => m.ChannelId == channelId &&
                                                   m.MonitoredName == productName &&
                                                   m.MonitoredUrl == productUrl).FirstOrDefault();

            if (mr == null)
            {
                return;
            }

            decimal?currentPrice = CanonMapping.GetCurrentMapPrice(channelId, productName, productUrl);

            if (currentPrice == null)
            {
                return;
            }

            if ((decimal)currentPrice == price)
            {
                CanonProductsLog.Add(channelId, mr.ProductId, MappingLogEnum.PriceWithoutChanges);
            }
            else
            {
                CanonProductsLog.Add(channelId, mr.ProductId, MappingLogEnum.NewPrice, price.ToString());
            }
        }
예제 #9
0
        protected override void BindData()
        {
            CanonDataContext db = Cdb.Instance;

            gridResellers.DataSource = db.Resellers.Where(r => r.ResellerGroup.IsDeleted == false).ToList();
            gridResellers.DataBind();
        }
예제 #10
0
        /// <summary>
        /// Create new user.
        /// </summary>
        /// <param name="user"></param>
        public int CreateUser(User user)
        {
            CanonDataContext db = Cdb.Instance;

            if (Business.User.IsLoginExists(user.UserName))
            {
                throw new LoginExistsException(user.UserName);
            }

            string cleanPassword = string.Empty;

            //insert a new user
            user.IsForbidden = false;
            cleanPassword    = user.Password;
            user.Password    = EncodePassword(cleanPassword);
            db.Users.InsertOnSubmit(user);
            db.SubmitChanges();

            if (!string.IsNullOrEmpty(user.Email))
            {
                EmailGateway.Send(
                    String.Empty,
                    user.Email,
                    Utilities.GetResourceString("Common", "EmailCredentialsSubject"),
                    String.Format(Utilities.GetResourceString("Common", "EmailCredentialsText"), user.UserName, cleanPassword),
                    new List <Attachment>());
            }

            return(user.UserId);
        }
예제 #11
0
        /// <summary>
        /// Inserts new record into db
        /// </summary>
        public bool InsertNewRecord()
        {
            CanonDataContext db = Cdb.Instance;

            //check if name is not started with stop words from FeedProductExceptions
            List <FeedProductException> flist = db.FeedProductExceptions.ToList();

            foreach (FeedProductException fpe in flist)
            {
                if (this.ProductName.ToUpper().StartsWith(fpe.StopWord))
                {
                    return(false);
                }
            }

            ChannelMonitor rec = new ChannelMonitor();

            rec.ChannelId   = this.ChannelId;
            rec.ImportDate  = DateTime.Now;
            rec.Price       = this.Price;
            rec.PriceVat    = this.PriceVat;
            rec.ProductDesc = Utilities.TruncateString(this.ProductDesc, 1000);
            rec.ProductName = Utilities.TruncateString(this.ProductName, 1000);
            rec.ProductUrl  = Utilities.TruncateString(this.ProductUrl, 1000);
            rec.Vat         = this.Vat;

            //Check price is changed !!! BEFORE submit
            this.CheckIfPriceIsChanged(this.ChannelId, rec.ProductName, rec.ProductUrl, rec.PriceVat);

            db.ChannelMonitors.InsertOnSubmit(rec);
            db.SubmitChanges();
            return(true);
        }
예제 #12
0
파일: User.cs 프로젝트: radtek/canon
        public static void UpdateCategoryRelation(int userId, int catId, bool relationExist)
        {
            CanonDataContext db = Cdb.Instance;

            try
            {
                UsersCategory uc = db.UsersCategories.First(u => u.UserId == userId && u.CategoryId == catId);
                if (!relationExist)
                {
                    db.UsersCategories.DeleteOnSubmit(uc);
                }
            }
            catch (Exception)
            {
                //there is no suc relation
                if (relationExist)
                {
                    UsersCategory newUc = new UsersCategory();
                    newUc.CategoryId = catId;
                    newUc.UserId     = userId;
                    db.UsersCategories.InsertOnSubmit(newUc);
                }
            }
            db.SubmitChanges();
        }
예제 #13
0
        /// <summary>
        /// Update user.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="previousLogin"></param>
        public void UpdateUser(User user, string previousLogin)
        {
            CanonDataContext db = Cdb.Instance;

            if (!String.Equals(user.UserName, previousLogin, StringComparison.CurrentCultureIgnoreCase))
            {
                if (Business.User.IsLoginExists(user.UserName))
                {
                    throw new LoginExistsException(user.UserName);
                }
            }

            var updatedUser = (from u in db.Users
                               where u.UserId == user.UserId &&
                               ((u.IsForbidden == false) || (u.IsForbidden == null))
                               select u).Single();

            updatedUser.FullName     = user.FullName;
            updatedUser.LastLogin    = user.LastLogin;
            updatedUser.UserName     = user.UserName;
            updatedUser.Email        = user.Email;
            updatedUser.IsDailyEmail = user.IsDailyEmail;
            updatedUser.IsForbidden  = false;
            updatedUser.IsActive     = user.IsActive;

            if (!String.IsNullOrEmpty(user.Password))
            {
                updatedUser.Password = EncodePassword(user.Password);
            }
            db.SubmitChanges();
        }
예제 #14
0
        public static void InsertImportDistributor(ImportDistributor newValue)
        {
            CanonDataContext db = Cdb.Instance;

            db.ImportDistributors.InsertOnSubmit(newValue);
            db.SubmitChanges();
        }
예제 #15
0
        public RecommendedPrice InsertUpdatePrice(Product updated)
        {
            CanonDataContext db          = Cdb.Instance;
            RecommendedPrice imported    = this.RecommendedPrices[0];
            RecommendedPrice recommended = db.RecommendedPrices.FirstOrDefault(u => u.ProductId == updated.ProductId &&
                                                                               u.ChangeDate.Date == DateTime.Now.Date);

            if (recommended == null)
            {
                recommended = new RecommendedPrice();
                db.RecommendedPrices.InsertOnSubmit(recommended);
            }
            recommended.Price      = imported.Price;
            recommended.ProductId  = updated.ProductId;
            recommended.ChangeDate = DateTime.Now;
            recommended.UserId     = WebVariables.LoggedUserId;
            if (IsLastRecommendedPriceDifferent(recommended))
            {
                //add into log that price is changed
                CanonProductsLog.Add(ProductsLogEnum.PriceIsChanged, recommended.ProductId,
                                     recommended.Price.ToString(), WebVariables.LoggedUserId);
                CanonProductsLog.AddRecommendedLog(WebVariables.LoggedUserId,
                                                   updated.ProductId,
                                                   RecommendedChangeSourceEnum.Import,
                                                   recommended.Price, recommended.ChangeDate);
            }
            db.SubmitChanges();
            return(recommended);
        }
예제 #16
0
        protected override void BindData()
        {
            CanonDataContext db = Cdb.Instance;

            gridDistributorsManage.DataSource = db.Distributors.Where(d => d.IsDeleted == false).ToList();
            gridDistributorsManage.DataBind();
        }
예제 #17
0
        protected override void BindData()
        {
            CanonDataContext db = Cdb.Instance;

            gridDistributors.DataSource = db.ImportDistributors.Where(d => d.Succeeded == true);
            gridDistributors.DataBind();
        }
예제 #18
0
        public static void InsertImportReseller(ImportReseller newValue)
        {
            CanonDataContext db = Cdb.Instance;

            db.ImportResellers.InsertOnSubmit(newValue);
            db.SubmitChanges();
        }
예제 #19
0
        public static ManualImportQueue GetLatestQueueElement(int channelId)
        {
            CanonDataContext  db    = Cdb.Instance;
            ManualImportQueue queue =
                db.ManualImportQueues.OrderByDescending(q => q.PostDate).FirstOrDefault(p => p.ChannelId == channelId);

            return(queue);
        }
예제 #20
0
        public void DeleteRelevanceWords(Product updated)
        {
            CanonDataContext db = Cdb.Instance;
            var found           = db.ProductsRelevances.Where(r => r.ProductId == updated.ProductId);

            db.ProductsRelevances.DeleteAllOnSubmit(found);
            db.SubmitChanges();
        }
예제 #21
0
        public List<ImportErrorMessage> InsertImportPriceListRecord(CanonDataContext db)
        {
            List<ImportErrorMessage> warnings = new List<ImportErrorMessage>();

            // CanonDataContext db = Cdb.Instance;

            // Create Product Group if it doesn't exist yet
            ProductGroup productGroup = db.ProductGroups.FirstOrDefault(pg => pg.Code == this.ProductCategory);
            if (productGroup == null)
            {
                productGroup = new ProductGroup();
                productGroup.Code = this.ProductCategory;
                productGroup.FileAs = "Nová_" + this.ProductCategory;

                db.ProductGroups.InsertOnSubmit(productGroup);
            }

            // create Product type if it doesn't exist in DB yet
            ProductType pType = db.ProductTypes.FirstOrDefault(pt => pt.Type == this.ProductType);
            if (pType == null)
            {
                pType = new ProductType();
                pType.Type = this.ProductType;

                db.ProductTypes.InsertOnSubmit(pType);
            }

            // update product
            Product product = db.Products.FirstOrDefault(p => p.ProductCode == this.ProductCode);
            if (product == null)
            {
                product = new Product();
                product.IsActive = true;

                db.Products.InsertOnSubmit(product);
            }

            product.ProductCode = this.ProductCode;
            product.ProductName = this.ProductName;
            product.ProductGroup = productGroup;
            product.CurrentPrice = this.ListPrice;
            product.ProductType = pType;

            // insert ImportPriceListRecord
            ImportPriceListRecord record = new ImportPriceListRecord();
            record.IDImportPriceList = this.ImportPriceList.ID;
            record.ListPrice = this.ListPrice;
            record.ProductCode = this.ProductCode;
            record.ProductName = this.ProductName;
            record.ProductCategory = this.ProductCategory;
            record.ProductType = this.ProductType;

            db.ImportPriceListRecords.InsertOnSubmit(record);
            db.SubmitChanges();

            return warnings;
        }
예제 #22
0
        public static void UpdateCategoryById(int id, CanonCategory newValues)
        {
            CanonDataContext db  = Cdb.Instance;
            Category         cat = db.Categories.First(u => u.CategoryId == id);

            cat.CategoryName = newValues.CategoryName;
            cat.InternalId   = newValues.InternalId;
            db.SubmitChanges();
        }
예제 #23
0
        public bool ExportToDb()
        {
            ErrorMessages.Clear();

            try
            {
                bool     IsSucceeded = false;
                List <T> list        = this.ImportFile(ref IsSucceeded);
                if (IsSucceeded == false)
                {
                    return(false);
                }

                CanonDataContext db = Cdb.Instance;

                // Create ImportDistributor
                ImportDistributor importDistributor = new ImportDistributor();
                importDistributor.IDDistributor = DistributorId;
                importDistributor.IDUser        = WebVariables.LoggedUserId;
                importDistributor.FileName      = _OriginalFilename;
                importDistributor.DateImported  = DateTime.Now;
                importDistributor.DateFrom      = DateTime.Now;
                importDistributor.DateTo        = importDistributor.DateFrom.AddDays(30);
                importDistributor.ErrorMessage  = string.Empty;
                importDistributor.Succeeded     = true;
                importDistributor.IsDeleted     = false;

                CanonImportDistributor.InsertImportDistributor(importDistributor);

                // import Distributor records
                foreach (T record in list)
                {
                    try
                    {
                        record.ImportDistributor = importDistributor;
                        record.InsertImportDistributorRecord();
                    }
                    catch (Exception ex)
                    {
                        //add message about error
                        ErrorMessages.Add(new ImportErrorMessage("GeneralRecordImportError",
                                                                 new string[] { "Reseller", record.ResellerIdentificationNumber + "_" + record.ResellerName }));
                        //into log
                        WebVariables.Logger.Error(string.Format("File {0}, general import error", _filename), ex);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorMessages.Add(new ImportErrorMessage("GeneralFileImportError"));
                //into log
                WebVariables.Logger.Error(string.Format("File {0} ", _filename), ex);
                return(false);
            }

            return(true);
        }
예제 #24
0
        /// <summary>
        /// Binding main grid based on current conditions
        /// </summary>
        protected override void BindData()
        {
            CanonDataContext db = Cdb.Instance;

            gridPriceHistory.DataSource = db.RecommendedPrices.OrderByDescending(p => p.ChangeDate).Where(
                m => m.ProductId == this.CurrentProduct);
            gridPriceHistory.DataBind();
            RecommendedHistoryCtrl.Parameters = new int[] { (int)this.CurrentProduct };
            RecommendedHistoryCtrl.Bind();
        }
예제 #25
0
        /// <summary>
        /// Check if user's login exists.
        /// </summary>
        /// <param name="login"></param>
        /// <returns></returns>
        public bool IsLoginExists(string login)
        {
            CanonDataContext db = Cdb.Instance;

            int count = db.Users.Count(u => u.UserName == login &&
                                       ((u.IsForbidden == false) ||
                                        (u.IsForbidden == null)));

            return(count != 0);
        }
예제 #26
0
        protected override void BindData()
        {
            CanonDataContext db = Cdb.Instance;

            // logss for the last 30 days
            DateTime date = DateTime.Now.AddDays(-30);

            gridPricesImportsLog.DataSource = db.ImportPriceLists.Where(p => p.Succeeded == true && p.DateImported >= date).OrderByDescending(p => p.DateImported).ToList();
            gridPricesImportsLog.DataBind();
        }
예제 #27
0
        public static List <MainMonitor> GetValuesForChart(DateTime date1, DateTime date2,
                                                           List <int> channels, List <int> products)
        {
            CanonDataContext   db   = Cdb.Instance;
            List <MainMonitor> list = db.MainMonitors.OrderByDescending(m => m.CalcDate).Where(
                w => w.CalcDate.Date >= date1.Date && w.CalcDate.Date <= date2.Date &&
                products.Contains(w.ProductId) && channels.Contains(w.ChannelId)).ToList();

            return(list);
        }
예제 #28
0
        public static void InsertCategory(CanonCategory newValues)
        {
            CanonDataContext db  = Cdb.Instance;
            Category         cat = new Category();

            cat.CategoryName = newValues.CategoryName;
            cat.InternalId   = newValues.InternalId;
            db.Categories.InsertOnSubmit(cat);
            db.SubmitChanges();
        }
예제 #29
0
        /// <summary>
        /// Get all locale resources.
        /// </summary>
        public static List <Canon.Data.Localization> GetAllLocaleResources(string locale)
        {
            CanonDataContext db = Cdb.Instance;

            var resources = from l in db.Localizations
                            where l.LocaleId == locale
                            select l;

            return(resources.ToList());
        }
예제 #30
0
        public List <MappingRule> GetMappingRules()
        {
            if ((ChannelIds == null) || (ChannelIds.Count == 0))
            {
                return(null);
            }
            CanonDataContext   db   = Cdb.Instance;
            List <MappingRule> maps = db.MappingRules.Where(m => ChannelIds.Contains(m.ChannelId)).ToList();

            return(maps);
        }
예제 #31
0
파일: User.cs 프로젝트: radtek/canon
        /// <summary>
        /// Delete user by id.
        /// </summary>
        /// <param name="userId"></param>
        public static void DeleteUserById(int userId)
        {
            //user deletion
            CanonDataContext db = Cdb.Instance;

            Canon.Data.User user = db.Users.First(u => u.UserId == userId);
            //db.Users.DeleteOnSubmit(user);
            user.IsForbidden = true;
            db.SubmitChanges();
            CleanUsersCache();
        }