public Model.SubPurchase AddSubpurchasePhone(string phone, string name, string surname, bool validated) { //string phoneLikeExpression = MakePhoneLikeExpression(phone); var selectPhone = _context.SubPurchasePhones .FirstOrDefault(p => p.phone == phone); if (selectPhone == null) { var addingSubPurchase = new Model.SubPurchase() { id = Guid.NewGuid(), name = name, surname = surname, not_checked = !validated, createDate = Utils.GetUkranianDateTimeNow(), modifyDate = Utils.GetUkranianDateTimeNow() }; _context.SubPurchases.InsertOnSubmit(addingSubPurchase); _context.SubmitChanges(); this.AddSubpurchasePhone(phone, addingSubPurchase); return(addingSubPurchase); } else { return(selectPhone.SubPurchase); } }
protected void dlCheckSubPurchases_UpdateCommand(object source, DataListCommandEventArgs e) { CheckBox chkChecked; chkChecked = (CheckBox)(e.Item.FindControl("chkCheckedSubPurchase")); bool checkedState = chkChecked.Checked; Label subpurchaseIdLabel; subpurchaseIdLabel = (Label)(e.Item.FindControl("subpurchaseId")); //--- save into DB var editItemKey = Guid.Parse(subpurchaseIdLabel.Text); var subPurchase = (from subPurch in _dbcontext.SubPurchases where subPurch.id == editItemKey select subPurch).SingleOrDefault(); _dbcontext.SubPurchases.Attach(subPurchase); subPurchase.not_checked = checkedState; _dbcontext.SubmitChanges(); //--- end save into DB if (!checkedState) { if (subPurchase != null) { //--- remove Advertisments with current SubPurchase var subPurchaseAdvertisments = from advertisment in _dbcontext.Advertisments join advertismentPhone in _dbcontext.AdvertismentPhones on advertisment.Id equals advertismentPhone.AdvertismentId join subpruchasePhone in _dbcontext.SubPurchasePhones on advertismentPhone.phone equals subpruchasePhone.phone where subpruchasePhone.SubPurchaseId == editItemKey select advertisment; if (subPurchaseAdvertisments.Count() > 0) { foreach (var adv in subPurchaseAdvertisments) { adv.not_show_advertisment = true; } _dbcontext.SubmitChanges(); } } } dlCheckSubPurchases.EditItemIndex = -1; dlCheckSubPurchases.DataBind(); }
public Model.SearchResult AddSearchResult(int parsedAdvertismentsCount = 0) { var advertSection = (from section in _dbcontext.AdvertismentSections where section.code == _sectionCode select section).SingleOrDefault(); if (advertSection == null) { throw new Exception("Section name with code '" + _sectionCode + "' was not founded"); } var searchResults = from lastSearchResultFromDB in _dbcontext.SearchResults where lastSearchResultFromDB.AdvertismentSection.code == _sectionCode orderby lastSearchResultFromDB.createDate descending select lastSearchResultFromDB; Model.SearchResult searchResult; Model.SearchResult lastSearchResult = null; if (searchResults.Any()) { lastSearchResult = searchResults.Take(1).SingleOrDefault(); } if (lastSearchResult != null && lastSearchResult.createDate.Date == Utils.GetUkranianDateTimeNow().Date) { lastSearchResult.modifyDate = Utils.GetUkranianDateTimeNow(); lastSearchResult.allParsedAdvertismentsCount = parsedAdvertismentsCount; searchResult = lastSearchResult; } else { searchResult = new Model.SearchResult { createDate = Utils.GetUkranianDateTimeNow(), modifyDate = Utils.GetUkranianDateTimeNow(), AdvertismentSection = advertSection, allParsedAdvertismentsCount = parsedAdvertismentsCount }; _dbcontext.SearchResults.InsertOnSubmit(searchResult); } _dbcontext.SubmitChanges(); return(searchResult); }
protected void dlCheckSubPurchases_DeleteCommand(object source, DataListCommandEventArgs e) { //--- save into DB var subpurchasesContext = new Model.DataModel(); Label subpurchaseIdLabel; subpurchaseIdLabel = (Label)(e.Item.FindControl("subpurchaseId")); var editItemKey = Guid.Parse(subpurchaseIdLabel.Text); var subPurchase = new Model.SubPurchase() { id = editItemKey }; subpurchasesContext.SubPurchases.Attach(subPurchase); subpurchasesContext.SubPurchases.DeleteOnSubmit(subPurchase); subpurchasesContext.SubmitChanges(); //--- end save into DB dlCheckSubPurchases.EditItemIndex = -1; dlCheckSubPurchases.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { string editAdvIDText = Request["edit"]; if (!string.IsNullOrEmpty(editAdvIDText)) { int editAdvID; if (int.TryParse(editAdvIDText, out editAdvID)) { var workflow = new AdvertismentsWorkflow(); if (workflow.ExistsAdvertisment(editAdvID, Authorization.Authorization.CurrentUser_UserID())) { editAdvertismentID = editAdvID; } } } if (editAdvertismentID != null) { if (Request.Form.Count == 0) { var dataModel = new Model.DataModel(); txtText.Text = dataModel.Advertisments .Where(a => a.Id == editAdvertismentID) .Select(a => a.text) .FirstOrDefault(); rptPhones.DataSource = dataModel.AdvertismentPhones .Where(p => p.AdvertismentId == editAdvertismentID); rptPhones.DataBind(); } else { var dataModel = new Model.DataModel(); int?authorizedUserID = Authorization.Authorization.CurrentUser_UserID(); if (!authorizedUserID.HasValue) { return; } var advertisment = dataModel.Advertisments .FirstOrDefault(a => a.Id == editAdvertismentID && a.UserID == authorizedUserID.Value); if (advertisment != null) { advertisment.text = txtText.Text; string phoneIDsForm = Request.Form["phoneId"]; string[] phoneIDs = phoneIDsForm.Split(','); foreach (string phoneID in phoneIDs) { int phoneIDInt; if (!int.TryParse(phoneID, out phoneIDInt)) { continue; } string phoneEdited = Request.Form["phones[" + phoneID + "].phone"]; var phone = dataModel.AdvertismentPhones .FirstOrDefault(p => p.Id == phoneIDInt && p.AdvertismentId == editAdvertismentID); if (phone != null) { phone.phone = phoneEdited; } } dataModel.SubmitChanges(); Response.Redirect(Request.Url.AbsolutePath); } } } else { var userID = Authorization.Authorization.CurrentUser_UserID(); if (userID.HasValue) { ldsAdvertisments.WhereParameters["UserID"].DefaultValue = userID.ToString(); } else { Response.Redirect("~/failed-authorization"); } } }