public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Added,CreditLimit")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Qty,Status")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("DoorKey,RoomNo,Level,CustName,Id,Note")] Rooms rooms)
        {
            if (ModelState.IsValid)
            {
                rooms.Id = Guid.NewGuid();
                _context.Add(rooms);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rooms));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Quantity,Date")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                Restock(product);
                return(RedirectToAction(nameof(Index)));
            }

            return(View(product));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("CustName,RoomId,Id,Note")] Movement movement)
        {
            if (ModelState.IsValid)
            {
                movement.Id = Guid.NewGuid();
                _context.Add(movement);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["RoomId"] = new SelectList(_context.Rooms, "Id", "Id", movement.RoomId);
            return(View(movement));
        }
Ejemplo n.º 6
0
 public IActionResult Add(Product product)
 {
     dbContext.Add(product);
     dbContext.SaveChanges();
     return(Ok(product.Id));
 }
Ejemplo n.º 7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseAuthentication();

            //app.UseCors(CorsOptions.AllowAll);

            //لعمل محاكاة لمستخدم قام بتسجيل الدخول حتى نجرب العمل

            app.Use(async(context, next) =>
            {
                string userName = context.Request.Query["userName"];
                //string userName2 = context.Request.Body["userName"];
                //string userName2 = context.Request.Form["userName"];
                if (!string.IsNullOrEmpty(userName) && userName != "undefined" && !userName.Equals("null"))
                {
                    MyDB mydb   = new MyDB();
                    MyUser user = null;
                    try { user = mydb.MyUsers.FirstOrDefault(x => x.UserName == userName); } catch { }
                    try
                    {
                        if (user == null)
                        {
                            user = new MyUser {
                                UserName = userName, Id = Guid.NewGuid(), Date1 = DateTime.Now, Note = "fromWebSite"
                            };
                            mydb.Add(user);
                            mydb.SaveChanges();
                        }
                    }
                    catch (Exception)
                    {
                    }

                    var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                    identity.AddClaim(new Claim(ClaimTypes.Name, userName));
                    identity.AddClaim(new Claim(ClaimTypes.Role, "ChatRole"));

                    if (userName.ToLower().Contains("admin"))
                    {
                        identity.AddClaim(new Claim(ClaimTypes.Role, "Admin"));
                    }
                    context.User = new ClaimsPrincipal(identity);
                }
                await next();
            }
                    );
            app.UseSignalR((routes) =>
            {
                routes.MapHub <MyHub>("/MyHub");
                routes.MapHub <NotificationHub>("/Notifi");
                // routes.MapHub<CalcHub>("/calcHub");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }