// GET: Home public ActionResult Index() { List <Product> SetPrice = new List <Product>(); using (var ctx = new AuctionSiteDBEntities()) { var listget = ctx.Auctions.ToList(); var listmax = ctx.Products.Where(p => p.Bought == false && (DateTime.Now <= EntityFunctions.AddDays(p.TimePost, p.IntervalTime))).OrderByDescending(p => p.PriceDisplay).ToList().Take(5); var listend = ctx.Products.Where(p => p.Bought == false && (DateTime.Now <= EntityFunctions.AddDays(p.TimePost, p.IntervalTime))) .OrderBy(p => (EntityFunctions.DiffSeconds(DateTime.Now, EntityFunctions.AddDays(p.TimePost, p.IntervalTime)))).ToList().Take(5); var TopSetPriceList = listget.GroupBy(a => a.IDPro).OrderByDescending(a => a.Key).ToList().Take(5); foreach (var id in TopSetPriceList) { Product pro = ctx.Products.Where(p => p.ID == id.Key && p.Bought == false).FirstOrDefault(); if (pro != null) { SetPrice.Add(pro); } } HomeVM vm = new HomeVM(); vm.MostSettingPrice = new List <Product>(); vm.MaxPrice = new List <Product>(); vm.EndDate = new List <Product>(); vm.EndDate.AddRange(listend); vm.MostSettingPrice.AddRange(SetPrice); vm.MaxPrice.AddRange(listmax); return(View(vm)); } }
public void TimeDiffSeconds() { TimeSpan time = stored.Add(TimeSpan.FromSeconds(-1)); #if !EFOLD var q = this.Entities .Where(x => DbFunctions.DiffSeconds(time, x.Time) == 1); #else var q = this.Entities .Where(x => EntityFunctions.DiffSeconds(time, x.Time) == 1); #endif q.Should().NotBeEmpty(); }
public void DateTimeDiffSeconds() { DateTime date = stored.AddSeconds(-1); #if !EFOLD var q = this.Entities .Where(x => DbFunctions.DiffSeconds(date, x.DateTime) == 1); #else var q = this.Entities .Where(x => EntityFunctions.DiffSeconds(date, x.DateTime) == 1); #endif q.Should().NotBeEmpty(); }
public void DateTimeOffsetDiffSeconds() { DateTimeOffset offset = stored.AddSeconds(-1); #if !EFOLD var q = this.Entities .Where(x => DbFunctions.DiffSeconds(offset, x.Offset) == 1); #else var q = this.Entities .Where(x => EntityFunctions.DiffSeconds(offset, x.Offset) == 1); #endif q.Should().NotBeEmpty(); }
public List <R_ReportByBusinessModel> GetLongestWaitingBusiness(int num) // Khách hàng có thời gian chờ lâu nhất { using (db = new QMSSystemEntities()) { List <R_ReportByBusinessModel> list = null; var today = DateTime.Now.Date; // chi lay phan ngay thang nam ko lay gio phut giay try { //Tao 1 list chua danh sach khach hang da giao dich xong hoac dang giao dich //Tao 1 list khach hang van dang doi // Them 2 list tren vao mot list thu 3 // Truy van dieu kien tren list thu 3 chon ra cac khach hang co thoi gian doi lau nhat list = db.Q_DailyRequire_Detail.Where(x => !x.Q_User.IsDeleted && !x.Q_Major.IsDeleted && !x.Q_DailyRequire.Q_Service.IsDeleted && x.ProcessTime.HasValue && EntityFunctions.TruncateTime(x.ProcessTime.Value) == today).Select(x => new R_ReportByBusinessModel() { //Index = i, UserId = x.UserId, MajorId = x.MajorId, ServiceId = x.Q_DailyRequire.ServiceId, UserName = x.Q_User.Name, TicketNumber = x.Q_DailyRequire.TicketNumber, MajorName = x.Q_Major.Name, //EquipmentName = x.Q_Equipment.Name, PrintTime = x.Q_DailyRequire.PrintTime, ProcessTime = x.ProcessTime, EndProcessTime = x.EndProcessTime, //TotalTransTime = x.EndTransTime.Value.Subtract(x.StartTransTime.Value), }).OrderByDescending(x => EntityFunctions.DiffSeconds(x.PrintTime.Value, x.ProcessTime.Value)).Take(num).ToList(); if (list.Count > 0) { int i = 1; foreach (var item in list) { item.Index = i++; item.TotalWaitingTime = (item.PrintTime.HasValue && item.ProcessTime.HasValue) ? item.ProcessTime.Value.Subtract(item.PrintTime.Value) : (TimeSpan?)null; } } return(list); } catch (Exception ex) { throw ex; } } }
public List <R_ReportByBusinessModel> GetLongestTransBusiness(int num) // Lay n khach hang co thoi gian giao dich lau nhat { using (db = new QMSSystemEntities()) { List <R_ReportByBusinessModel> list = null; var today = DateTime.Now.Date; // chi lay phan ngay thang nam ko lay gio phut giay //var today = DateTime.Now.AddDays(-1).Date; // Lay ngay truoc do 1 ngay try { list = db.Q_DailyRequire_Detail.Where(x => !x.Q_User.IsDeleted && !x.Q_Major.IsDeleted && !x.Q_DailyRequire.Q_Service.IsDeleted && x.ProcessTime.HasValue && x.EndProcessTime.HasValue && EntityFunctions.TruncateTime(x.ProcessTime.Value) == today).Select(x => new R_ReportByBusinessModel() { //Index = i, UserId = x.UserId, MajorId = x.MajorId, ServiceId = x.Q_DailyRequire.ServiceId, UserName = x.Q_User.Name, TicketNumber = x.Q_DailyRequire.TicketNumber, MajorName = x.Q_Major.Name, // CounterName = x.Q_Equipment.Q_Counter.Name, PrintTime = x.Q_DailyRequire.PrintTime, ProcessTime = x.ProcessTime, EndProcessTime = x.EndProcessTime, //TotalTransTime = x.EndTransTime.Value.Subtract(x.StartTransTime.Value), }).OrderByDescending(x => EntityFunctions.DiffSeconds(x.ProcessTime.Value, x.EndProcessTime.Value)).Take(num).ToList(); if (list.Count > 0) { int i = 1; foreach (var item in list) { item.Index = i++; item.TotalTransTime = (item.ProcessTime.HasValue && item.EndProcessTime.HasValue) ? item.EndProcessTime.Value.Subtract(item.ProcessTime.Value) : (TimeSpan?)null; } } return(list); } catch (Exception ex) { throw ex; } } }
public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r) { if (k.Equals("RefreshBids")) { // do stuff here if it matches our taskname, like WebRequest // re-add our task so it recurs var finishedListings = db.Listings.Where(l => EntityFunctions.DiffSeconds(l.EndTimestamp, DateTime.Now) > 0); foreach (var listing in finishedListings) { // If there are no closing histories found for the listing // Only create closing histories for "won" auctions if (!db.ClosingHistories.Any(ch => ch.ListingID == listing.ListingID) && listing.Bids.Count > 0) { // Get the winning bid (dirty workaround) Bid winningBid = null; foreach (var b in listing.Bids.OrderByDescending(l => l.Timestamp).Take(1)) { winningBid = b; } // Save data to closing history ClosingHistory ch = new ClosingHistory(); ch.BidID = winningBid.BidID; ch.Bid = winningBid; ch.ListingID = listing.ListingID; ch.Listing = listing; ch.UserID = winningBid.UserID; ch.User = winningBid.User; // Save closing history to db db.ClosingHistories.Add(ch); } } db.SaveChanges(); } AddTask(k, Convert.ToInt32(v)); }
public ActionResult QuickAttendanceRecord(int memberId, int disciplineId) { ViewBag.IsLocked = ApplicationContext.CurrentApplicationContext.CurrentSession.AttendanceLock; // Get selected member Member member = db.GetDbSet <Member>().Where(m => m.Id == memberId).FirstOrDefault(); // Find the class session going on right now for given discipline. DateTime dtNow = DateTime.Now; int dow = (int)dtNow.DayOfWeek; var classSessionQuery = from cs in db.GetDbSet <ClassSession>().Include("Discipline") where cs.DisciplineId == disciplineId && cs.StartTime <= dtNow && cs.EndTime >= dtNow && (int)cs.DayOfWeek == dow select cs; ClassSession classSession = classSessionQuery.FirstOrDefault(); // If class session is null... if (classSession == null) { // Find the closest class session to now from the given disipline. classSessionQuery = from cs in db.GetDbSet <ClassSession>().Include("Discipline") where cs.DisciplineId == disciplineId && (int)cs.DayOfWeek == dow orderby EntityFunctions.DiffSeconds(cs.StartTime, dtNow), EntityFunctions.DiffSeconds(cs.EndTime, dtNow) select cs; classSession = classSessionQuery.FirstOrDefault(); } // If class session or member is null.. if (classSession == null || member == null) { // Return an error. return(Json(new { Error = true })); } else { // Check if member is already checked in. bool alreadyCheckedIn = db.GetDbSet <AttendanceSheet>().Any(a => a.MemberId == member.Id && a.ClassSessionId == classSession.Id && DbFunctions.TruncateTime(a.AttendanceDate) == DbFunctions.TruncateTime(dtNow)); // If the member is not currently checked in... if (!alreadyCheckedIn) { // Create attendance record for member. AttendanceSheet sheet = new AttendanceSheet() { AttendanceDate = dtNow, MemberId = member.Id, ClassSessionId = classSession.Id }; db.GetDbSet <AttendanceSheet>().Add(sheet); db.SaveChanges(); } // Return that member has been checked in and class session checked in for. return(Json(new { Error = false, checkedIn = alreadyCheckedIn, classSession = $"{classSession.Discipline.Name} {classSession.StartTime.ToString("h:mm tt")} - {classSession.EndTime.ToString("h:mm tt")}", member = member.FullName })); } }
public ActionResult Activate(PurchasedItemModel model, string returnUrl) { if (!ModelState.IsValid) { return(Redirect("Index")); } string facilityName = model.Facility; string userName = model.Name; string email = model.Email; string dateOfPurchase = model.DateOfPurchase; List <PurchasedItem> purchasedItems = GetStoredPurchasedItems(); if (purchasedItems == null) { return(LogOutAndRedirectToLoginPage()); } DateTime date = DateTime.Parse(dateOfPurchase); var purchasedItem = purchasedItems.Find(i => Math.Abs(i.DateOfPurchase.Subtract(date).TotalSeconds) < 1); if (purchasedItem != null) { var count = context.UserPurchases.Where(u => EntityFunctions.DiffSeconds(u.DateOfPurchase, purchasedItem.DateOfPurchase) < 1).Count(); //if(count != 0) // return Content("<html><head></head><body><h1>Error! This item already activated </h1></body></html>"); var salt = GenerateSequenceOfChars(20); // TODO: check facility name length var password = GeneratePassword(facilityName); //TODO: move following code to method var userPurchase = new UserPurchase(); userPurchase.Email = email; userPurchase.ActivatorsEmail = User.Identity.Name; userPurchase.Name = userName; userPurchase.PasswordSalt = salt; userPurchase.Password = HashPassword(password, salt); userPurchase.FacilityName = facilityName; userPurchase.DateOfPurchase = purchasedItem.DateOfPurchase; userPurchase.UserRegistrationDate = DateTime.Now; userPurchase.UserExpirationDate = DateTime.Now.AddMonths(6); context.UserPurchases.Add(userPurchase); context.SaveChanges(); HttpContext.Session["lastPurchase"] = userPurchase; HttpContext.Session["lastPurchasePassword"] = password; //Send an email to user IMailService mailService = new SmptMailService(System.Configuration.ConfigurationManager.AppSettings["smtpServer"]); MailContent mailContent = new MailContent(); mailContent.MailFrom = "*****@*****.**"; mailContent.MailingAdress = userPurchase.Email; mailContent.Subject = "AFFI FSMA Self-Assessment Login Credentials and Instructions"; mailContent.HtmlText = "<html><head></head><body>Dear " + userPurchase.Name + ":<br/>" + "<p>When you want to begin your FSMA Self-Assessment for your facility (<b>" + userPurchase.FacilityName + "</b>), you can just click on the Login link below.</p>" + "<p>Your login credentials for the FSMA Self-Assessment are: </p>" + "<p><b>Userid: </b>" + userPurchase.Email + "</p>" + "<p><b>Password: </b>" + password + "</p>" + "<p>If you have any questions regarding the FSMA Self-Assessment Tool, please contact AFFI Vice President of Regulatory and Technical Affairs Dr. Donna Garren at <a href=\"mailto:[email protected]\">[email protected]</a> or (703) 821-0770.</p>" + "<p>Thank you.</p>" + "<p><a href=\"http://affi-fsma.seneca.com/signIn\" target=\"_blank\">Click Here to Login</a></p></body></html>"; mailContent.PlainText = mailContent.HtmlText; mailService.sendMail(mailContent); //And if needed - to a person who had activated the purchase (if not same person) if (userPurchase.Email != userPurchase.ActivatorsEmail) { mailContent.MailingAdress = userPurchase.ActivatorsEmail; mailService.sendMail(mailContent); } return(Redirect("Index")); } else { return(Content("<html><head></head><body><h1>Error!Can't find purchasedItem</h1></body></html>")); } }
public List <DispatchDetails> GetOrderDispatches(int orderId) { if (UserHelper.IsAuthorize(new List <int> { (int)UserType.SuperAdmin, (int)UserType.Admin, (int)UserType.Client })) { try { List <DispatchDetails> result = new List <DispatchDetails>(); List <Orders_Positions> listOfOrdersPositions = _context.Orders_Positions.Where(o => o.Order_id == orderId && o.Deleted_At == null).ToList(); Delivery delivery = _context.Deliveries.FirstOrDefault(d => d.Order_Id == orderId && d.Deleted_At == null); List <Deliveries_Dispatches> listOfDeliveryDispatches = _context.Deliveries_Dispatches.Where(d => d.Delivery_Id == delivery.Id && d.Deleted_At == null).ToList(); foreach (var deliveryDispatch in listOfDeliveryDispatches) { Dispatch dispatch = _context.Dispatches.FirstOrDefault(d => d.Id == deliveryDispatch.Dispatch_Id && d.Deleted_At == null); DispatchDetails dispatchDetails = new DispatchDetails(); CarrierDispatch carrierDispatch = new CarrierDispatch(); ReceiverDispatch receiverDispatch = new ReceiverDispatch(); List <OrderPositionsDispatchInfo> listOfOrderPositionsDispatchInfo = new List <OrderPositionsDispatchInfo>(); List <Dispatches_Positions> listOfDispatchPositions = new List <Dispatches_Positions>(); foreach (var item in listOfOrdersPositions) { var dispatchPosition = _context.Dispatches_Positions.FirstOrDefault(d => d.Order_Position_Id == item.Id && d.Dispatch_Id == dispatch.Id && d.Deleted_At == null); if (dispatchPosition != null) { var dispatchesPositionsForOrderPosition = _context.Dispatches_Positions.Where(d => d.Order_Position_Id == item.Id && EntityFunctions.DiffSeconds(d.Created_At, dispatchPosition.Created_At) < 0 && d.Deleted_At == null).OrderBy(d => d.Created_At).ToList(); int? dispatchedAmount = dispatchesPositionsForOrderPosition.Sum(d => d.Amount); decimal?dispatchedWeight = dispatchesPositionsForOrderPosition.Sum(d => d.Weight_Gross); OrderPositionsDispatchInfo orderPositionsDispatchInfo = new OrderPositionsDispatchInfo(); orderPositionsDispatchInfo.Id = item.Id; orderPositionsDispatchInfo.Name = item.Name; orderPositionsDispatchInfo.Amount = item.Amount; orderPositionsDispatchInfo.Amount_Received = item.Amount_Received; orderPositionsDispatchInfo.Amount_Before_Dispatch = item.Amount_Received - dispatchedAmount; orderPositionsDispatchInfo.Amount_Dispatch = dispatchPosition.Amount; orderPositionsDispatchInfo.Amount_After_Dispatch = orderPositionsDispatchInfo.Amount_Before_Dispatch - orderPositionsDispatchInfo.Amount_Dispatch; orderPositionsDispatchInfo.Weight_Gross = item.Weight_Gross; orderPositionsDispatchInfo.Weight_Gross_Received = item.Weight_Gross_Received; orderPositionsDispatchInfo.Weight_Before_Dispatch = item.Weight_Gross_Received - dispatchedWeight; orderPositionsDispatchInfo.Weight_Dispatch = dispatchPosition.Weight_Gross; orderPositionsDispatchInfo.Weight_After_Dispatch = orderPositionsDispatchInfo.Weight_Before_Dispatch - orderPositionsDispatchInfo.Weight_Dispatch; listOfOrderPositionsDispatchInfo.Add(orderPositionsDispatchInfo); } } carrierDispatch.Carrier_Name = dispatch.Carrier_Name; carrierDispatch.Carrier_Email = dispatch.Carrier_Email; carrierDispatch.Carrier_Address = dispatch.Carrier_Address; carrierDispatch.Carrier_PrefixVat_Id = dispatch.Carrier_PrefixVat_Id; carrierDispatch.Carrier_VAT_Id = dispatch.Carrier_VAT_Id; carrierDispatch.Carrier_PhoneNumber = dispatch.Carrier_PhoneNumber; receiverDispatch.Receiver_Name = dispatch.Receiver_Name; receiverDispatch.Receiver_Email = dispatch.Receiver_Email; receiverDispatch.Receiver_Address = dispatch.Receiver_Address; receiverDispatch.Receiver_PrefixVat_Id = dispatch.Receiver_PrefixVat_Id; receiverDispatch.Receiver_VAT_Id = dispatch.Receiver_VAT_Id; receiverDispatch.Receiver_PhoneNumber = dispatch.Receiver_PhoneNumber; dispatchDetails.Id = dispatch.Id; dispatchDetails.Dispatch_Number = dispatch.Dispatch_Number; dispatchDetails.Creation_Date = dispatch.Creation_Date == null ? string.Empty : ((DateTime)(dispatch.Creation_Date)).ToString("dd-MM-yyyy"); dispatchDetails.Car_Id = dispatch.Car_Id; dispatchDetails.Carrier = carrierDispatch; dispatchDetails.Receiver = receiverDispatch; dispatchDetails.ListOfOrderPositions = listOfOrderPositionsDispatchInfo; result.Add(dispatchDetails); } return(result); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } } else { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "User don't have acces to this method")); } }