public IQueryable <TopProducts> GetTopProducts() { XbooxLibraryDBContext db = new XbooxLibraryDBContext(); GeneralRepository <Order> otable = new GeneralRepository <Order>(db); GeneralRepository <OrderDetails> odtable = new GeneralRepository <OrderDetails>(db); GeneralRepository <Product> ptable = new GeneralRepository <Product>(db); var temp = from od in odtable.GetAll() join o in otable.GetAll() on od.OrderId equals o.OrderId join p in ptable.GetAll() on od.ProductId equals p.ProductId where o.Paid == true //paid 付款狀態 註解掉可以取得較多data select new { Year = o.OrderDate.Year, Month = o.OrderDate.Month, Name = p.Name, Quantity = od.Quantity }; var topproducts = from t in temp group t by new { t.Year, t.Month, t.Name } into g select new TopProducts { Month = g.Key.Month, Name = g.Key.Name, Quantity = g.Sum(x => x.Quantity) }; return(topproducts); }
//ActivatingUser public JsonExecuteResult ActivatingUser(long user_id) { User user = GetUser(user_id); if (user == null) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The user doesn't exist. Operation failed")); } if (user.UserStatus_ID == (byte)Consts.UserStatus.Active) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The user status is Active already. Operation failed.")); } try { user.UserStatus_ID = (byte)Consts.UserStatus.Active; user.IsConfirmed = true; GeneralRepository.SubmitChanges(dataContext); Mail.SendApprovalConfirmation(user.Email, user.Login, user.AddressCard_Billing.FirstName, user.AddressCard_Billing.LastName); } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS)); }
public OperationResult AddToCart() { OperationResult operationResult = new OperationResult(); using (var transaction = DbContext.Database.BeginTransaction()) { try { var CartRepo = new GeneralRepository <Cart>(DbContext); var GetUserKey = GetCookieKey(); var cart = CartRepo.GetFirst(x => x.CartId.ToString() == GetUserKey); if (cart == null) { cart = new Cart { CartId = Guid.Parse(GetUserKey), UserId = HttpContext.Current.User.Identity.Name }; CartRepo.Create(cart); } CartRepo.SaveContext(); operationResult.isSuccessful = true; transaction.Commit(); return(operationResult); } catch (Exception ex) { operationResult.isSuccessful = false; operationResult.exception = ex; transaction.Rollback(); return(operationResult); } } }
public void Get_AddOneGetOtherId_ReturnsNull() { bool error = false; GeneralClass returned = null; Guid id = Guid.NewGuid(); var name = "Name 1"; try { var item = new GeneralClass { Id = id, Name = name }; var repository01 = new GeneralRepository(); repository01.Reset(); repository01.Set(item); returned = repository01.Get(Guid.NewGuid()); } catch (Exception e) { error = true; } Assert.IsFalse(error); Assert.IsNull(returned); }
protected void btnSave_Click(object sender, EventArgs e) { bool rs = false; using (GeneralRepository <DAL.Sql.Modles.Course> repository = new GeneralRepository <DAL.Sql.Modles.Course>()) { DAL.Sql.Modles.Course data = null; if (CourseID != -1) { data = repository.Find(x => x.CourseID == CourseID).FirstOrDefault(); rs = repository.Update(GetData(data)); lblSatusInfo.Text = rs ? "Updating is successful!" : "Updating had been failed!"; } else { data = new DAL.Sql.Modles.Course(); rs = repository.Add(GetData(data)) > 0; lblSatusInfo.Text = rs ? "Inserting is successful!" : "Inserting had been failed!"; } } if (rs) { PopulateControls(); } }
public void Delete(Guid id) { XbooxLibraryDBContext context = new XbooxLibraryDBContext(); GeneralRepository <Product> repository = new GeneralRepository <Product>(context); GeneralRepository <ProductImgs> Imgrepository = new GeneralRepository <ProductImgs>(context); GeneralRepository <ProductTags> Ptrepository = new GeneralRepository <ProductTags>(context); var deleteProduct = repository.GetFirst(x => x.ProductId == id); var deleteImg = Imgrepository.GetAll().Where(x => x.ProductId == id); var deleteTag = Ptrepository.GetAll().Where(x => x.ProductId == id); if (deleteImg != null) { foreach (var i in deleteImg) { Imgrepository.Delete(i); } } if (deleteTag != null) { foreach (var i in deleteTag) { Ptrepository.Delete(i); } } //刪除product 刪除 tag repository.Delete(deleteProduct); context.SaveChanges(); }
public void Set_AddNull_NotStoredAndNotError() { bool error = false; List <GeneralClass> preList = null; List <GeneralClass> postList = null; try { GeneralClass item = null; var repository = new GeneralRepository(); repository.Reset(); preList = repository.GetAll().ToList(); repository.Set(item); postList = repository.GetAll().ToList(); } catch (Exception e) { error = true; } Assert.IsFalse(error); Assert.IsNotNull(preList); Assert.IsNotNull(postList); Assert.IsTrue(preList.Count() == 0); Assert.IsTrue(postList.Count() == 0); }
/// <summary> /// 取得所有訂單 /// </summary> /// <returns></returns> public List <OrderViewModel> GetOrder() { using (var dbContext = new XbooxLibraryDBContext()) { var orderRepo = new GeneralRepository <Order>(dbContext); var userRepo = new GeneralRepository <AspNetUsers>(dbContext); var orderList = (from o in orderRepo.GetAll().AsEnumerable() join user in userRepo.GetAll().AsEnumerable() on o.UserId equals user.Id select new OrderViewModel { OrderId = o.OrderId, OrderDate = (DateTime)TimeCheckerService.GetTaipeiTime(o.OrderDate), UserName = user.UserName, PurchaserName = o.PurchaserName, PurchaserEmail = o.PurchaserEmail, PurchaserAddress = $"{o.City}{o.District}{o.Road}", PurchaserPhone = o.PurchaserPhone, Payment = o.Payment, Paid = o.Paid, PayDate = TimeCheckerService.GetTaipeiTime(o.PayDate), Build = o.Build }).OrderBy(item => item.OrderDate).ToList(); return(orderList); } }
/// <summary> /// 拿到訂單裡的產品資訊 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public List <OrderDetailsViewModel> GetOrderDetails(string orderId) { using (var dbContext = new XbooxLibraryDBContext()) { var orderDetailRepo = new GeneralRepository <OrderDetails>(dbContext); var productRepo = new GeneralRepository <Product>(dbContext); var imgRepo = new GeneralRepository <ProductImgs>(dbContext); var CouponRepo = new GeneralRepository <Coupons>(dbContext); List <OrderDetailsViewModel> orderDetailsList = new List <OrderDetailsViewModel>(); // 因為多張圖片會重複產品 var tempList = (from od in orderDetailRepo.GetAll().AsEnumerable() where od.OrderId.ToString() == orderId join pd in productRepo.GetAll().AsEnumerable() on od.ProductId equals pd.ProductId join pi in imgRepo.GetAll().AsEnumerable() on pd.ProductId equals pi.ProductId where pd.ProductId == pi.ProductId select new OrderDetailsViewModel { Imagelink = pi.imgLink, Name = pd.Name, Quantity = od.Quantity, Price = pd.Price, Coupon = CouponRepo.GetFirst(item => item.Id == od.Discount), Total = Math.Round(pd.Price * od.Quantity) }).GroupBy(item => item.Name); foreach (var productList in tempList) { var firstProductItem = productList.FirstOrDefault(item => !item.Imagelink.Contains("-0")); orderDetailsList.Add(firstProductItem); } return(orderDetailsList); } }
public ActionResult Index(int?page, DateTime?FromDate, DateTime?ToDate) { var ts = SessionStore.GetTravelSession(); //var agents = ser.GetAgentsList().Where(x => x.CreatedBy == ts.AppUserId); var agents = ser.GetAgentsList().Where(x => x.DistributorId == ts.LoginTypeId); ViewData["Agents"] = new SelectList(agents, "AgentId", "AgentName"); int currentPageIndex = page.HasValue ? page.Value : 1; int defaultPageSize = 30; PendingBookingModel model = new PendingBookingModel(); if (FromDate == null && ToDate == null) { model.FromDate = GeneralRepository.CurrentDateTime().AddDays(-15); model.ToDate = GeneralRepository.CurrentDateTime(); } else { model.FromDate = FromDate; model.ToDate = ToDate; } //var agentsByDistributor = distributorManagementProvider.GetAllAgentsByDistributorId(ts.AppUserId); //var details = ser.ListPendingBookintReport(model.AgentId, model.FromDate, model.ToDate); //var result = agentsByDistributor.SelectMany(b => details.Where(x => x.AgentId == b.AgentId).ToList()); var details = ser.ListPendingBookintReport(model.AgentId, model.FromDate, model.ToDate); var result = details.Where(x => x.DistributorId == ts.LoginTypeId); model.PendingBookingList = result.ToPagedList(currentPageIndex, defaultPageSize); return(View(model)); }
public async Task <IHttpActionResult> GetProjectDocuments(int projectId) { var generalRepository = new GeneralRepository <ProjectDocuments>(new AppDbContext()); var documentData = await generalRepository.GetAllItems(p => p.ProjectId == projectId); return(Ok(documentData)); }
//刪除 public OperationResult DeleteOrder(string id) { OperationResult operationResult = new OperationResult(); var dbContext = new XbooxLibraryDBContext(); using (var transaction = dbContext.Database.BeginTransaction()) { try { var orderRepo = new GeneralRepository <Order>(dbContext); var orderDetailRepo = new GeneralRepository <OrderDetails>(dbContext); var productRepo = new GeneralRepository <Product>(dbContext); var orderDetails = orderDetailRepo.GetAll().Where(item => item.OrderId.ToString() == id); var order = orderRepo.GetFirst(item => item.OrderId.ToString() == id); if (order != null && orderDetails != null) { foreach (var item in orderDetails) { orderDetailRepo.Delete(item); } orderRepo.Delete(order); productRepo.SaveContext(); operationResult.IsSuccessful = true; transaction.Commit(); } } catch (Exception ex) { operationResult.IsSuccessful = false; operationResult.exception = ex; transaction.Rollback(); } } return(operationResult); }
public ActionResult Index(int?page, DateTime?FromDate, DateTime?ToDate) { TravelSession obj = (TravelSession)Session["TravelPortalSessionInfo"]; AgentCallLogModel model = new AgentCallLogModel(); if (FromDate == null && ToDate == null) { model.FromDate = GeneralRepository.CurrentDateTime().Date; model.ToDate = GeneralRepository.CurrentDateTime().Date.AddHours(23).AddMinutes(59); } else { model.FromDate = FromDate; model.ToDate = ToDate; } int currentPageIndex = page.HasValue ? page.Value : 1; int defaultPageSize = 30; model.AgentCallLogList = ser.ListPhoneCallLogs(model.FromDate, model.ToDate); model.AgentFollowUpCallLogList = ser.ListFollowUpPhoneCallLogs().ToPagedList(currentPageIndex, defaultPageSize); return(View(model)); }
/// <summary> /// Transform All books' type to ProductDetailViewModel type /// </summary> /// <returns></returns> public static IEnumerable <ProductDetailViewModel> FindBookDetail() { var ProductRepo = new GeneralRepository <Product>(_context); var ProductImgsRepo = new GeneralRepository <ProductImgs>(_context); var CategoryRepo = new GeneralRepository <Category>(_context); var ProductTagsRepo = new GeneralRepository <ProductTags>(_context); var TagsRepo = new GeneralRepository <Tags>(_context); var Products = ProductRepo.GetAll().ToList().Select(x => new ProductDetailViewModel() { Name = x.Name, Price = x.Price, CategoryID = x.CategoryId.ToString(), ProductId = x.ProductId.ToString(), UnitInStock = x.UnitInStock, ISBN = x.ISBN, Publisher = x.Publisher, Description = x.Description, Specification = x.Specification, Author = x.Author, Intro = x.Intro, Language = x.Language, ImgLinks = ProductImgsRepo.GetAll().Where(q => q.ProductId == x.ProductId).Select(j => j.imgLink).ToList(), ImgLink = ProductImgsRepo.GetFirst(y => y.ProductId == x.ProductId).imgLink, PublishedDate = x.PublishedDate.ToString("yyyy/MM/dd"), CategoryName = CategoryRepo.GetFirst(z => z.CategoryId == x.CategoryId).Name, TagId = ProductTagsRepo.GetFirst(z => z.ProductId == x.ProductId).TagId.ToString(), TagName = TagsRepo.GetFirst(y => y.TagId == _context.ProductTags.FirstOrDefault(k => k.ProductId == x.ProductId).TagId).TagName }); return(Products); }
public GeneralRepository.BoolResponse SaveDetails() { if (string.IsNullOrEmpty(contactData.Name)) { contactData.Name = ""; } using (GeneralRepository objCR = new GeneralRepository()) { GeneralRepository.BoolResponse saveStatus = objCR.SavePockup(this.contactData); if (saveStatus.status == 0) { airbornefrs.Data.AppEmail.AppEmails appEmail = new airbornefrs.Data.AppEmail.AppEmails(airbornefrs.Data.AppEmail.AppEmails.EmailSettingIDs.contactus); string body = appEmail.MAIL.Body; body = body.Replace("#Name#", contactData.Name).Replace("#Email#", contactData.Email).Replace("#CompanyName#", contactData.CompanyName).Replace("#ReasonInquiry#", contactData.ReasonInquiry).Replace("#Product#", contactData.Product).Replace("#IMEI#", contactData.IMEI).Replace("#AdditionalInfo#", contactData.AdditionalInfo); appEmail.MAIL.Body = body; appEmail.MAIL.Subject = appEmail.MAIL.Subject + " : " + contactData.Name; airbornefrs.Framework.BoolResponse response = appEmail.FireEmail(); saveStatus.status = response.status; saveStatus.message = response.message; } return(saveStatus); } }
/// <summary> /// 拿到記住訂單的資訊 /// </summary> /// <param name="httpContext"></param> /// <returns></returns> public OrderViewModel GetRecordInfo(HttpContextBase httpContext) { using (var dbContext = new XbooxLibraryDBContext()) { var orderRepo = new GeneralRepository <Order>(dbContext); var userRepo = new GeneralRepository <AspNetUsers>(dbContext); var userId = httpContext.User.Identity.GetUserId(); var orderList = orderRepo.GetAll() .Where(item => item.UserId == userId) .OrderByDescending(item => item.OrderDate); var order = orderList.FirstOrDefault(); OrderViewModel orderInfo = new OrderViewModel(); if (order != null) { if (order.Remember) { orderInfo.PurchaserName = order.PurchaserName; orderInfo.City = order.City; orderInfo.District = order.District; orderInfo.Road = order.Road; orderInfo.PurchaserEmail = order.PurchaserEmail; orderInfo.PurchaserPhone = order.PurchaserPhone; orderInfo.Remember = order.Remember; } } return(orderInfo); } }
public List <ProductListViewModel> GetProducts() { XbooxLibraryDBContext context = new XbooxLibraryDBContext(); GeneralRepository <Product> prepository = new GeneralRepository <Product>(context); // var tagList = Tagrepository.GetAll().ToList(); var pList = prepository.GetAll().Select(item => new ProductListViewModel { Name = item.Name, Author = item.Author, CategoryId = item.CategoryId, Intro = item.Intro, ISBN = item.ISBN, Price = item.Price, PublishedDate = item.PublishedDate, Publisher = item.Publisher, UnitInStock = item.UnitInStock, Specification = item.Specification, ProductId = item.ProductId, Description = item.Description, Language = item.Language }).ToList(); return(pList); }
/// <summary> /// 編輯當筆訂單的付款狀態(ecpayNumber) /// </summary> /// <param name="ecpayNumber"></param> /// <returns></returns> public OperationResult EditPaidStateByEcNumber(string ecpayNumber) { OperationResult operationResult = new OperationResult(); using (var dbContext = new XbooxLibraryDBContext()) { try { var orderRepo = new GeneralRepository <Order>(dbContext); var order = orderRepo.GetFirst(x => x.EcpayOrderNumber.ToString() == ecpayNumber); if (order != null) { if (!order.Paid) { order.Paid = true; order.PayDate = DateTime.UtcNow; } else { order.Paid = false; } orderRepo.SaveContext(); operationResult.isSuccessful = true; } } catch (Exception ex) { operationResult.isSuccessful = false; operationResult.exception = ex; } return(operationResult); } }
public void RemoveImg(string imgName) { XbooxLibraryDBContext context = new XbooxLibraryDBContext(); GeneralRepository <Product> repository = new GeneralRepository <Product>(context); GeneralRepository <ProductImgs> Imgrepository = new GeneralRepository <ProductImgs>(context); var charac = imgName.Split('"'); foreach (var i in charac) { Debug.WriteLine(i); } var temp = charac[1]; var imgToDelete = Imgrepository.GetAll().FirstOrDefault(x => x.imgLink == temp); if (imgToDelete != null) { Imgrepository.Delete(imgToDelete); Imgrepository.SaveContext(); } else { } }
/// <summary> /// 利用訂單Id取訂單 /// </summary> /// <param name="httpContext"></param> /// <param name="orderId"></param> /// <returns></returns> public List <OrderViewModel> GetOrder(HttpContextBase httpContext, string orderId) { using (var dbContext = new XbooxLibraryDBContext()) { var orderRepo = new GeneralRepository <Order>(dbContext); var userRepo = new GeneralRepository <AspNetUsers>(dbContext); var userId = httpContext.User.Identity.GetUserId(); var orderList = (from o in orderRepo.GetAll().AsEnumerable() where o.UserId == userId && o.OrderId.ToString() == orderId join user in userRepo.GetAll().AsEnumerable() on o.UserId equals user.Id select new OrderViewModel { OrderId = o.OrderId, EcpayOrderNumber = o.EcpayOrderNumber, OrderDate = (DateTime)TimeCheckerService.GetTaipeiTime(o.OrderDate), UserName = user.UserName, PurchaserName = o.PurchaserName, PurchaserEmail = o.PurchaserEmail, City = o.City, District = o.District, Road = o.Road, PurchaserPhone = o.PurchaserPhone, Payment = o.Payment, PayDate = TimeCheckerService.GetTaipeiTime(o.PayDate), Paid = o.Paid, Build = o.Build }).OrderBy(item => item.OrderDate).ToList(); return(orderList); } }
public void Set_AddSameTwice_OnlyOneItem() { bool error = false; List <GeneralClass> list01 = null; Guid id = Guid.NewGuid(); var name = "Name 1"; try { var item = new GeneralClass { Id = id, Name = name }; var repository01 = new GeneralRepository(); repository01.Reset(); repository01.Set(item); repository01.Set(item); list01 = repository01.GetAll().ToList(); } catch (Exception e) { error = true; } Assert.IsFalse(error); Assert.IsNotNull(list01); Assert.IsTrue(list01.Count() == 1); }
protected void btnSave_Click(object sender, ImageClickEventArgs e) { int rs = 0; using (CourseEntities context = new CourseEntities()) { using (GeneralRepository <Category> repository = new GeneralRepository <Category>(context)) { if (CategoryID == -1) { if (repository.Find(x => x.Name == txtName.Text).Count() > 0) { nameCustomValidator.IsValid = false; } else { nameCustomValidator.IsValid = true; rs = repository.Add(GetData(new Category())); } } else { repository.Update(GetData(repository.Find(x => x.CategoryID == CategoryID).FirstOrDefault())); } } } if (rs > 0) { if (Submit_Click != null) { Submit_Click(); } } }
//UpdateStatementInvoice public JsonExecuteResult UpdateStatementInvoice(long invoice_id, int commissionrate_id, bool ispaid) { try { Invoice invoice = GetInvoice(invoice_id); if (invoice == null) { throw new Exception("The invoice doesn't exist."); } CommissionRate cr = dataContext.CommissionRates.SingleOrDefault(CR => CR.RateID == commissionrate_id); if (cr == null) { throw new Exception("The commission rate doesn't exist."); } Auction auction = dataContext.Auctions.SingleOrDefault(q => q.ID == invoice.Auction_ID); if (auction == null) { throw new Exception("The lot doesn't exist."); } auction.CommissionRate_ID = cr.RateID; GeneralRepository.SubmitChanges(dataContext); invoice.Cost = invoice.Amount - dataContext.GetComissionForItem(invoice.Auction_ID, invoice.Amount).GetPrice(); invoice.IsPaid = ispaid; invoice.Shipping = invoice.Tax = invoice.LateFee = 0; GeneralRepository.SubmitChanges(dataContext); } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS)); }
public OperationResult CouponsCreate(Coupons input) { var result = new OperationResult(); try { XbooxLibraryDBContext context = new XbooxLibraryDBContext(); GeneralRepository <Coupons> couRepo = new GeneralRepository <Coupons>(context); Coupons entity = new Coupons() { Id = Guid.NewGuid(), CouponName = input.CouponName, Discount = input.Discount, CouponCode = input.CouponCode, StartTime = input.StartTime, EndTime = input.EndTime }; couRepo.Create(entity); couRepo.SaveContext(); result.IsSuccessful = true; } catch (Exception ex) { result.IsSuccessful = false; result.exception = ex; } return(result); }
//DeleteUser public object DeleteUser(long user_id) { User user = GetUser(user_id); if (user == null) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The user doesn't exist. Operation failed")); } if ((!AppHelper.CurrentUser.IsRoot && (user.IsAdmin || user.IsRoot)) || (AppHelper.CurrentUser.ID == user.ID)) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't delete this user.")); } try { long count = dataContext.Auctions.Where(A => A.Owner_ID == user_id).Count(); if (count > 0) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't delete this user, because he is an owner of existing auctions in the system. You can set the status for this user as Inactive or delete all his auctions")); } count = dataContext.Consignments.Where(U => U.User_ID == user_id).Count(); if (count > 0) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't delete this user, because there is the consignor statement(s) for this user in the system. You can set the status for this user as Inactive or delete all the consignor statements.")); } dataContext.Users.DeleteOnSubmit(user); GeneralRepository.SubmitChanges(dataContext); } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS)); }
//DeleteEvent public object DeleteEvent(long event_id) { Event evnt = GetEvent(event_id); if (evnt == null) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "The event doesn't exist. Operation failed")); } int count = (from A in dataContext.Auctions where A.Event_ID == event_id select A).Count(); if (count > 0) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't delete this event because there are auctions which are reference to this event.")); } count = (from A in dataContext.Consignments where A.Event_ID == event_id select A).Count(); if (count > 0) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't delete this event because there are " + evnt.Consignments.Count.ToString() + " consignment statements which are reference to this event.")); } count = (from A in dataContext.UserInvoices where A.Event_ID == event_id select A).Count(); if (count > 0) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, "You can't delete this event because there are " + evnt.UserInvoices.Count.ToString() + " users invoices which are reference to this event.")); } try { dataContext.Events.DeleteOnSubmit(evnt); GeneralRepository.SubmitChanges(dataContext); } catch (Exception ex) { return(new JsonExecuteResult(JsonExecuteResultTypes.ERROR, ex.Message)); } return(new JsonExecuteResult(JsonExecuteResultTypes.SUCCESS)); }
public OperationResult EmptyCart(string id) { OperationResult operationResult = new OperationResult(); using (var transaction = DbContext.Database.BeginTransaction()) { try { var CartItemsRepo = new GeneralRepository <CartItems>(DbContext); var GetUserKey = GetCookieKey(); var cartItems = CartItemsRepo.GetAll().Where(x => x.CartId.ToString() == GetUserKey && x.ProductId.ToString() == id).ToList(); foreach (var cartItem in cartItems) { CartItemsRepo.Delete(cartItem); } CartItemsRepo.SaveContext(); operationResult.isSuccessful = true; transaction.Commit(); return(operationResult); } catch (Exception ex) { operationResult.isSuccessful = false; operationResult.exception = ex; transaction.Rollback(); return(operationResult); } } }
protected void repCategories_ItemCommand(object source, RepeaterCommandEventArgs e) { bool rs = false; if (e.CommandName == "UpdateIsActive") { int id = Convert.ToInt32(e.CommandArgument); using (GeneralRepository <Category> repository = new GeneralRepository <Category>()) { Category cata = repository.Find(x => x.CategoryID == id).FirstOrDefault(); cata.IsActive = !cata.IsActive; rs = repository.Update(cata); } } else if (e.CommandName == "edit") { EditIndex = e.Item.ItemIndex; } //if (rs) //{ PopulateControls(); //} }
public void CancelPNR(Int64 PNRId, int userid) { PNRs result = _ent.PNRs.Where(x => x.PNRId == PNRId).FirstOrDefault(); if (result != null) { result.TicketStatusId = 2; result.UpdatedBy = userid; result.UpdatedDate = GeneralRepository.CurrentDateTime(); _ent.ApplyCurrentValues(result.EntityKey.EntitySetName, result); _ent.SaveChanges(); } else { TBO_MasterPNRs tboResult = _ent.TBO_MasterPNRs.Where(x => x.MPNRId == PNRId).FirstOrDefault(); if (tboResult != null) { tboResult.TicketStatusId = 2; tboResult.UpdatedBy = userid; tboResult.UpdatedDate = GeneralRepository.CurrentDateTime(); _ent.ApplyCurrentValues(tboResult.EntityKey.EntitySetName, tboResult); _ent.SaveChanges(); } } }
public IEnumerable <SalesRevenueViewModel> GetSalesRevenue() { XbooxLibraryDBContext db = new XbooxLibraryDBContext(); GeneralRepository <Order> otable = new GeneralRepository <Order>(db); GeneralRepository <OrderDetails> odtable = new GeneralRepository <OrderDetails>(db); GeneralRepository <Product> ptable = new GeneralRepository <Product>(db); var temp = from od in odtable.GetAll().AsEnumerable() join o in otable.GetAll().AsEnumerable() on od.OrderId equals o.OrderId join p in ptable.GetAll().AsEnumerable() on od.ProductId equals p.ProductId where o.Paid == true //paid 付款狀態 註解掉可以取得較多data select new { Year = o.OrderDate.Year, Month = o.OrderDate.Month, Total = p.Price * od.Quantity }; var Revenue = from t in temp group t by new { t.Month, t.Year } into g select new SalesRevenueViewModel { Year = g.Key.Year, Month = g.Key.Month, Revenue = g.Sum(x => x.Total) }; return(Revenue); }