示例#1
0
        protected void grdMenuItems_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            if (grdMenuItems.Rows.Count > 1)
            {
                GridViewRow         row      = (GridViewRow)grdMenuItems.Rows[e.RowIndex];
                List <FoodMenuItem> QuesList = (List <FoodMenuItem>)Session["MenuItems"];
                //Label1.Text = grdEditQuestions.DataKeys[e.RowIndex].Value.ToString();
                int quesListInd = Convert.ToInt32(grdMenuItems.DataKeys[e.RowIndex].Value.ToString());

                InsertHandler deleteDB = new InsertHandler();

                if (deleteDB.DeleteMenuItem(QuesList[quesListInd - 1].id) > 0)
                {
                    Label1.Text = "You have Successfully Remove Food Menu Item";
                    ShowLabel(2000);
                }
                else
                {
                    Label1.Text = "Exception Occur in Deleteing Food Menu Item";
                    ShowLabel(2000);
                }
            }
            else
            {
                Label1.Text = "Cannot Perform Delete Operation You Should Have Minimum 1 Item Per Food Menu";
                ShowLabel(2000);  // Showing Label for 2 Seconds...........
            }
            InitGridView();
        }
示例#2
0
        protected void btnCheckOut_Click(object sender, EventArgs e)
        {
            if (Session["CartItems"] != null)
            {
                SelectHandler selectDB       = new SelectHandler();
                int           currentOrderID = selectDB.nextOrderID();

                List <Cart>   cartItems = (List <Cart>)Session["CartItems"];
                InsertHandler insertDB  = new InsertHandler();

                foreach (Cart c in cartItems)
                {
                    insertDB.InsertIntoPlacedOrder(c, currentOrderID);
                }

                DateTime currentDateTime = DateTime.Now;
                string   orderTime       = currentDateTime.ToString("yyyy-MM-dd HH:mm:ss");
                int      custID          = Convert.ToInt32(Session["UserID"].ToString());

                int insertRecord = insertDB.InsertIntoBillDetail(currentOrderID, custID, deliveryAddress.Text, orderTime);

                if (insertRecord > 0)
                {
                    Session["CartItems"] = null;
                    Page.Response.Redirect("dashboard.aspx");
                }
            }
            else
            {
                displayMsg(this, "Please Add Items to Your Cart and then Press Check Out");
            }
        }
示例#3
0
 public FileCacheEntry(string pfx, InsertHandler h, DateTime ts = new DateTime(), TimeSpan tp = new TimeSpan())
 {
     Prefix    = pfx;
     Handler   = h;
     Timestamp = ts;
     Timespan  = tp;
 }
示例#4
0
            public FileCacheEntry(FileCache cache, string prefix, string path, string filter, InsertHandler handler, TimeSpan timespan)
            {
                _prefix   = prefix;
                _path     = path;
                _handler  = handler;
                _timespan = timespan;
                _watcher  = new FileSystemWatcher();

                // Start the filesystem watcher
                StartWatcher(cache, path, filter);
            }
        public int registerNewMember()
        {
            int           retCode = 0;
            InsertHandler insertH = new InsertHandler();

            retCode = insertH.InsertIntoUserProfile(this.customerID, this.userName, this.email, this.phone, this.category, this.cust_address);
            if (retCode > 0)
            {
                retCode = insertH.InsertIntoUserAccount(this.memberAccount);
            }
            return(retCode);
        }
示例#6
0
        /// <summary>
        ///     Watchdog the file cache
        /// </summary>
        public void Watchdog(DateTime utc)
        {
            Monitor.Enter(_lock);

            // Watchdog for cache entries
            while (_entriesByTimestamp.Count > 0)
            {
                KeyValuePair <DateTime, String> entry = _entriesByTimestamp.First();
                if (!_entriesByKey.TryGetValue(entry.Value, out MemCacheEntry cachedValue))
                {
                    break;
                }

                if (cachedValue.Timestamp + cachedValue.Timespan <= utc)
                {
                    // Erase the cache entry with timeout
                    _entriesByKey.Remove(entry.Value);
                    _entriesByTimestamp.Remove(entry.Key);
                    continue;
                }

                break;
            }

            // Watchdog for cache paths
            while (_pathsByTimestamp.Count > 0)
            {
                KeyValuePair <DateTime, String> entry = _pathsByTimestamp.First();
                if (!_pathsByKey.TryGetValue(entry.Value, out FileCacheEntry cachedValue))
                {
                    break;
                }

                if (cachedValue.Timestamp + cachedValue.Timespan <= utc)
                {
                    // Update the cache path with timeout
                    String        path     = entry.Value;
                    String        prefix   = cachedValue.Prefix;
                    TimeSpan      timespan = cachedValue.Timespan;
                    InsertHandler handler  = cachedValue.Handler;
                    _pathsByTimestamp.Remove(entry.Key);
                    Monitor.Exit(_lock);
                    InsertPath(path, prefix, timespan, handler);
                    Monitor.Enter(_lock);
                    continue;
                }

                break;
            }
        }
示例#7
0
        protected void grdMenuItems_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "AddNew")
            {
                GridViewRow  row             = grdMenuItems.FooterRow;
                TextBox      itemName        = row.FindControl("txtItemName") as TextBox;
                TextBox      ingredients     = row.FindControl("txtDescription") as TextBox;
                TextBox      imageUrl        = row.FindControl("txtImageUrl") as TextBox;
                TextBox      itemPrice       = row.FindControl("itemPrice") as TextBox;
                DropDownList ddlItemCategory = row.FindControl("ddlItemCategory") as DropDownList;
                // Label1.Text = txt.Text;
                FoodMenuItem newItem = new FoodMenuItem();
                newItem.itemName        = itemName.Text;
                newItem.itemIngredients = ingredients.Text;
                newItem.itemImageUrl    = imageUrl.Text;
                float price = 0;
                float.TryParse(itemPrice.Text, out price);
                newItem.itemPrice = price;
                ItemCategory itemCategory = new ItemCategory();
                itemCategory.id           = Convert.ToInt32(ddlItemCategory.SelectedItem.Value);
                itemCategory.categoryName = ddlItemCategory.SelectedItem.Text;
                newItem.menuItemCategory  = itemCategory;

                List <FoodMenuItem> quesList = (List <FoodMenuItem>)Session["MenuItems"];
                int listInd = quesList.Count;
                newItem.id = quesList[listInd - 1].id;
                int oldId = newItem.id;
                //displayMsg(this,"OldID: " + oldId);
                oldId++;
                newItem.id = oldId;
                InsertHandler insertDB = new InsertHandler();
                if (insertDB.InsertIntoFoodMenu(newItem) > 0)
                {
                    Label1.Text = "New Item Added Successfully";
                }
                else
                {
                    Label1.Text = "Error Occur in Adding New Item";
                }
                InitGridView();
                ShowLabel(2000);
            }
        }
示例#8
0
        protected void grdMenuItems_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow  row             = (GridViewRow)grdMenuItems.Rows[e.RowIndex];
            TextBox      itemName        = row.FindControl("txtItemName") as TextBox;
            TextBox      ingredients     = row.FindControl("txtDescription") as TextBox;
            TextBox      imageUrl        = row.FindControl("txtImageUrl") as TextBox;
            TextBox      itemPrice       = row.FindControl("itemPrice") as TextBox;
            DropDownList ddlItemCategory = row.FindControl("ddlItemCategory") as DropDownList;

            int quesListInd = Convert.ToInt32(grdMenuItems.DataKeys[e.RowIndex].Value.ToString());
            List <FoodMenuItem> itemsList  = (List <FoodMenuItem>)Session["MenuItems"];
            FoodMenuItem        updateItem = itemsList[quesListInd - 1];

            updateItem.itemName        = itemName.Text;
            updateItem.itemIngredients = ingredients.Text;
            updateItem.itemImageUrl    = imageUrl.Text;
            float price = 0;

            float.TryParse(itemPrice.Text, out price);
            updateItem.itemPrice = price;
            ItemCategory itemCategory = new ItemCategory();

            itemCategory.id             = Convert.ToInt32(ddlItemCategory.SelectedItem.Value);
            itemCategory.categoryName   = ddlItemCategory.SelectedItem.Text;
            updateItem.menuItemCategory = itemCategory;

            InsertHandler updateDB = new InsertHandler();

            if (updateDB.updateFoodItem(updateItem) > 0)
            {
                Label1.Text = "Item is Updated Successfully";
            }
            else
            {
                Label1.Text = "Item is not Updated Successfully";
            }
            ShowLabel(2000);  // Showing Label for 2 Seconds...........
            grdMenuItems.EditIndex = -1;
            InitGridView();
        }
示例#9
0
        public async void InsertHandler_Should_Work(string id, string description, bool expected)
        {
            // Given
            IMediator mediator = ServiceProvider.GetService <IMediator>();

            MockEventPublisher   publisher  = new MockEventPublisher(mediator);
            MockSampleRepository repository =
                new MockSampleRepository(new Dictionary <string, Domain.Sample.Sample>());
            Mock <IUnitOfWork> uow                 = new Mock <IUnitOfWork>();
            MockSampleService  service             = new MockSampleService();
            Mock <ILogger <InsertRequest> > logger = new Mock <ILogger <InsertRequest> >();

            InsertHandler handler =
                new InsertHandler(publisher, repository, uow.Object, service, logger.Object);

            SampleDto item = new SampleDto {
                Id = id, Description = description
            };
            InsertRequest command = new InsertRequest(item);

            // When
            EntityResult <SampleDto> result = await handler.Handle(command, new CancellationToken());

            // Then
            List <ValidationResult> notValidNotifications =
                result.Notifications.Where(notification => !notification.IsValid).ToList();

            if (expected)
            {
                Assert.Empty(notValidNotifications);
                Assert.True(ContainsType(publisher.Notifications,
                                         typeof(DomainEvent <InsertRequest>)));
            }
            else
            {
                Assert.NotEmpty(notValidNotifications);
                Assert.False(ContainsType(publisher.Notifications,
                                          typeof(DomainEvent <InsertRequest>)));
            }
        }
示例#10
0
            private static EditHandler GetCurrentRowEditHandler(RowManager rowManager)
            {
                var currentRow = rowManager.CurrentRow;

                if (currentRow.IsVirtual)
                {
                    var virtualRowPlacement = rowManager.VirtualRowPlacement;
                    if (virtualRowPlacement == VirtualRowPlacement.Head)
                    {
                        return(InsertHandler.EditVirtualHead(rowManager));
                    }
                    else
                    {
                        Debug.Assert(virtualRowPlacement == VirtualRowPlacement.Tail);
                        return(InsertHandler.EditVirtualTail(rowManager));
                    }
                }
                else
                {
                    return(EditCurrentHandler.Singleton);
                }
            }
示例#11
0
        private bool InsertFileInternal(string path, string file, string key, TimeSpan timeout, InsertHandler handler)
        {
            try
            {
                key  = key.Replace('\\', '/');
                file = file.Replace('\\', '/');

                // Load the cache file content
                var content = File.ReadAllBytes(file);
                if (!handler(this, key, content, timeout))
                {
                    return(false);
                }

                using (new WriteLock(_lockEx))
                {
                    // Update entries by path map
                    _entriesByPath[path].Add(key);
                }

                return(true);
            }
            catch (Exception) { return(false); }
        }
示例#12
0
 public static Closure Create(AccessContext parentContext, InsertHandler action, int index, AccessContextItem item)
 {
     return new InsertClosure(parentContext, action, index, item);
 }
示例#13
0
 private static EditHandler GetInsertAfterHandler(RowManager rowManager, RowPresenter parent, RowPresenter child)
 {
     return(parent == null?InsertHandler.After(rowManager, child) : InsertChildHandler.After(parent, child));
 }
示例#14
0
        private bool InsertPathInternal(string path, string prefix, TimeSpan timeout, InsertHandler handler)
        {
            try
            {
                string keyPrefix = (string.IsNullOrEmpty(prefix) || (prefix == "/")) ? "/" : (prefix + "/");

                // Iterate through all directory entries
                foreach (var item in Directory.GetDirectories(path))
                {
                    string key = keyPrefix + HttpUtility.UrlDecode(Path.GetFileName(item));

                    // Recursively insert sub-directory
                    if (!InsertPathInternal(item, key, timeout, handler))
                    {
                        return(false);
                    }
                }

                foreach (var item in Directory.GetFiles(path))
                {
                    string key = keyPrefix + HttpUtility.UrlDecode(Path.GetFileName(item));

                    try
                    {
                        // Load the cache file content
                        var content = File.ReadAllBytes(item);
                        if (!handler(this, key, content, timeout))
                        {
                            return(false);
                        }
                    }
                    catch (Exception) { return(false); }
                }

                return(true);
            }
            catch (Exception) { return(false); }
        }
示例#15
0
 public InsertClosure(AccessContext parentContext, InsertHandler action, int index, AccessContextItem item) : base(parentContext)
 {
     _execute = action;
     _arg0 = index;
     _arg1 = item;
 }
示例#16
0
 public InsertClosure(AccessContext parentContext, InsertHandler action, int index, AccessContextItem item) : base(parentContext)
 {
     _execute = action;
     _arg0    = index;
     _arg1    = item;
 }
示例#17
0
        /// <summary>
        /// Insert a new cache path with the given timeout into the file cache
        /// </summary>
        /// <param name="path">Path to insert</param>
        /// <param name="prefix">Cache prefix (default is "/")</param>
        /// <param name="timeout">Cache timeout (default is 0 - no timeout)</param>
        /// <param name="handler">Cache insert handler (default is 'return cache.Add(key, value, timeout)')</param>
        /// <returns>'true' if the cache path was setup, 'false' if failed to setup the cache path</returns>
        public bool InsertPath(string path, string prefix = "/", TimeSpan timeout = new TimeSpan(), InsertHandler handler = null)
        {
            if (handler == null)
            {
                handler = (FileCache cache, string key, byte[] value, TimeSpan timespan) => cache.Add(key, value, timespan);
            }

            // Try to find and remove the previous path
            RemovePathInternal(path);

            // Insert the cache path
            if (!InsertPathInternal(path, prefix, timeout, handler))
            {
                return(false);
            }

            lock (_lock)
            {
                // Update the cache entry
                if (timeout.Ticks > 0)
                {
                    DateTime current = DateTime.UtcNow;
                    _timestamp = (current <= _timestamp) ? new DateTime(_timestamp.Ticks + 1) : current;
                    _pathsByKey.Add(path, new FileCacheEntry(prefix, handler, _timestamp, timeout));
                    _pathsByTimestamp.Add(_timestamp, path);
                }
                else
                {
                    _pathsByKey.Add(path, new FileCacheEntry(prefix, handler));
                }

                return(true);
            }
        }
示例#18
0
 public static Closure Create(AccessContext parentContext, InsertHandler action, int index, AccessContextItem item)
 {
     return(new InsertClosure(parentContext, action, index, item));
 }
示例#19
0
        private bool InsertPathInternal(string root, string path, string prefix, TimeSpan timeout, InsertHandler handler)
        {
            try
            {
                string keyPrefix = (string.IsNullOrEmpty(prefix) || (prefix == "/")) ? "/" : (prefix + "/");

                // Iterate through all directory entries
                foreach (var item in Directory.GetDirectories(path))
                {
                    string key = keyPrefix + Uri.UnescapeDataString(Path.GetFileName(item));

                    // Recursively insert sub-directory
                    if (!InsertPathInternal(root, item, key, timeout, handler))
                    {
                        return(false);
                    }
                }

                foreach (var item in Directory.GetFiles(path))
                {
                    string key = keyPrefix + Uri.UnescapeDataString(Path.GetFileName(item));

                    // Insert file into the cache
                    if (!InsertFileInternal(root, item, key, timeout, handler))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception) { return(false); }
        }
示例#20
0
        private Boolean InsertPathInternal(String path, String prefix, TimeSpan timeout, InsertHandler handler)
        {
            try
            {
                String keyPrefix = String.IsNullOrEmpty(prefix) || prefix == "/" ? "/" : prefix + "/";

                // Iterate through all directory entries
                if (Directory.GetDirectories(path)
                    .Select(item => new { item, key = keyPrefix + HttpUtility.UrlDecode(Path.GetFileName(item)) })
                    .SelectWhere(pair => !InsertPathInternal(pair.item, pair.key, timeout, handler), pair => pair.item)
                    .Any())
                {
                    return(false);
                }

                foreach (String item in Directory.GetFiles(path))
                {
                    String key = keyPrefix + HttpUtility.UrlDecode(Path.GetFileName(item));

                    try
                    {
                        // Load the cache file content
                        Byte[] content = File.ReadAllBytes(item);
                        if (!handler(this, key, content, timeout))
                        {
                            return(false);
                        }
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#21
0
        /// <summary>
        /// Insert a new cache path with the given timeout into the file cache
        /// </summary>
        /// <param name="path">Path to insert</param>
        /// <param name="prefix">Cache prefix (default is "/")</param>
        /// <param name="filter">Cache filter (default is "*.*")</param>
        /// <param name="timeout">Cache timeout (default is 0 - no timeout)</param>
        /// <param name="handler">Cache insert handler (default is 'return cache.Add(key, value, timeout)')</param>
        /// <returns>'true' if the cache path was setup, 'false' if failed to setup the cache path</returns>
        public bool InsertPath(string path, string prefix = "/", string filter = "*.*", TimeSpan timeout = new TimeSpan(), InsertHandler handler = null)
        {
            if (handler == null)
            {
                handler = (FileCache cache, string key, byte[] value, TimeSpan timespan) => cache.Add(key, value, timespan);
            }

            // Try to find and remove the previous path
            RemovePathInternal(path);

            using (new WriteLock(_lockEx))
            {
                // Add the given path to the cache
                _pathsByKey.Add(path, new FileCacheEntry(this, prefix, path, filter, handler, timeout));
                // Create entries by path map
                _entriesByPath[path] = new HashSet <string>();
            }

            // Insert the cache path
            if (!InsertPathInternal(path, path, prefix, timeout, handler))
            {
                return(false);
            }

            return(true);
        }
 /// <summary>
 /// Registers an insertion handler.
 /// <see cref="InsertHandler"/>
 /// </summary>
 public void RegisterInsertHandler(InsertHandler inserter)
 {
     this.insertionHandlers.Add(inserter);
 }