public static void DeleteChannelById(int id) { CanonDataContext db = Cdb.Instance; List <MainMonitor> mms = db.MainMonitors.Where(u => u.ChannelId == id).ToList(); Channel channel = db.Channels.First(u => u.ChannelId == id); db.MainMonitors.DeleteAllOnSubmit(mms); db.SubmitChanges(); db.Channels.DeleteOnSubmit(channel); db.SubmitChanges(); }
/// <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(); }
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(); }
public static void InsertImportPriceList(ImportPriceList newValue) { CanonDataContext db = Cdb.Instance; db.ImportPriceLists.InsertOnSubmit(newValue); db.SubmitChanges(); }
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); }
/// <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(); }
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); }
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(); }
public static void InsertImportDistributor(ImportDistributor newValue) { CanonDataContext db = Cdb.Instance; db.ImportDistributors.InsertOnSubmit(newValue); db.SubmitChanges(); }
public static void InsertImportReseller(ImportReseller newValue) { CanonDataContext db = Cdb.Instance; db.ImportResellers.InsertOnSubmit(newValue); db.SubmitChanges(); }
/// <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); }
/// <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); }
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(); }
public static void ActivateProduct(string ean, bool isActive) { CanonDataContext db = Cdb.Instance; Product product = db.Products.FirstOrDefault(p => p.ProductCode == ean); if (product != null) { product.IsActive = isActive; db.SubmitChanges(); } //remove mapping rules if product is deactivated if (!isActive) { var rules = db.MappingRules.Where(m => m.ProductId == product.ProductId); db.MappingRules.DeleteAllOnSubmit(rules); db.SubmitChanges(); } }
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; }
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(); }
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(); }
public static void AddNewSubscriber(int userId, int queueElemId) { CanonDataContext db = Cdb.Instance; ManualImportSubscriber subs = new ManualImportSubscriber(); subs.ManualImportId = queueElemId; subs.SubscriptDate = DateTime.Now; subs.UserId = userId; db.ManualImportSubscribers.InsertOnSubmit(subs); db.SubmitChanges(); }
/// <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(); }
public static void RemoveImportDistributor(int id) { CanonDataContext db = Cdb.Instance; ImportDistributor import = db.ImportDistributors.FirstOrDefault(d => d.ID == id); if (import != null) { import.IsDeleted = true; db.SubmitChanges(); } }
public static void RemoveSubscriber(int userId, int queueElemId) { CanonDataContext db = Cdb.Instance; ManualImportSubscriber subs = db.ManualImportSubscribers.Where(m => m.ManualImportId == queueElemId && m.UserId == userId).FirstOrDefault(); if (subs != null) { db.ManualImportSubscribers.DeleteOnSubmit(subs); db.SubmitChanges(); } }
/// <summary> /// Update localization. /// </summary> /// <param name="localization"></param> protected static void UpdateLocalization(Canon.Data.Localization localization) { CanonDataContext db = Cdb.Instance; if (db.Localizations.GetOriginalEntityState(localization) == null) { db.Localizations.Attach(localization, false); db.Refresh(RefreshMode.KeepCurrentValues, localization); } db.SubmitChanges(); }
/// <summary> /// Update user's last login. /// </summary> /// <param name="user"></param> public void UpdateUserLastLogin(User user) { CanonDataContext db = Cdb.Instance; var updatedUser = (from u in db.Users where u.UserId == user.UserId select u).Single(); updatedUser.LastLogin = DateTime.Now; db.SubmitChanges(); }
public static void DeleteProductGroupById(int id) { CanonDataContext db = Cdb.Instance; ProductGroup pg = db.ProductGroups.FirstOrDefault(p => p.ID == id); if (pg.Products.Count > 0) { throw new ProductAssignedException(pg.FileAs, pg.Products.Count); } db.ProductGroups.DeleteOnSubmit(pg); db.SubmitChanges(); }
public static void DeleteCategoryById(int id) { CanonDataContext db = Cdb.Instance; Category category = db.Categories.First(u => u.CategoryId == id); int productsCount = db.Products.Count(p => p.CategoryId == category.CategoryId); if (productsCount > 0) { throw new ProductAssignedException(category.CategoryName); } db.Categories.DeleteOnSubmit(category); db.SubmitChanges(); }
public static void UpdateChannelById(int id, CanonChannel newValues) { CanonDataContext db = Cdb.Instance; Channel channel = db.Channels.First(u => u.ChannelId == id); channel.ChannelName = newValues.ChannelName; channel.ChannelType = newValues.ChannelType; channel.InfoType = newValues.InfoType; channel.IsActive = newValues.IsActive; channel.Url = newValues.Url; channel.ReportingTo = newValues.ReportingTo; db.SubmitChanges(); }
public void MarkRecommendeedRelevances() { CanonDataContext db = Cdb.Instance; Dictionary <int, int> recommended = this.ChooseBestPairs(); foreach (KeyValuePair <int, int> pair in recommended) { CurrentRelevance relevance = db.CurrentRelevances.First(r => r.ChannelMonitorId == pair.Value && r.ProductId == pair.Key); relevance.BestForMapping = true; } db.SubmitChanges(); }
public static void DeleteDistributorById(int id) { CanonDataContext db = Cdb.Instance; Distributor distributor = db.Distributors.FirstOrDefault(d => d.ID == id); if (distributor.ImportDistributors.Count > 0) { throw new ImportAssignedException(distributor.FileAs, distributor.ImportDistributors.Count); } db.Distributors.DeleteOnSubmit(distributor); db.SubmitChanges(); }
public static void DeleteResellerGroupById(int id) { CanonDataContext db = Cdb.Instance; ResellerGroup rg = db.ResellerGroups.FirstOrDefault(r => r.ID == id); if (rg.Resellers.Count > 0) { throw new ResellerAssignedException(rg.FileAs, rg.Resellers.Count); } db.ResellerGroups.DeleteOnSubmit(rg); db.SubmitChanges(); }
public static void AddChannelToQueue(int userId, int channelId) { CanonDataContext db = Cdb.Instance; ManualImportQueue newElem = new ManualImportQueue(); newElem.ChannelId = channelId; newElem.UserId = userId; newElem.Status = (int)ManualImportStatusEnum.WaitingInQueue; newElem.PostDate = DateTime.Now; db.ManualImportQueues.InsertOnSubmit(newElem); db.SubmitChanges(); CanonManualImport.AddNewSubscriber(userId, newElem.RecordId); }
public static void InsertChannel(CanonChannel newValues) { CanonDataContext db = Cdb.Instance; Channel channel = new Channel(); channel.ChannelName = newValues.ChannelName; channel.ChannelType = newValues.ChannelType; channel.InfoType = newValues.InfoType; channel.IsActive = newValues.IsActive; channel.Url = newValues.Url; channel.ReportingTo = newValues.ReportingTo; db.Channels.InsertOnSubmit(channel); db.SubmitChanges(); }