Пример #1
0
        public async Task <IActionResult> Create([Bind("id,class_id,course_id,teacher_id,year_id,class_time")] Routine routine)
        {
            var data = await _context.Routine
                       .FirstOrDefaultAsync(m => (m.teacher_id == routine.teacher_id && m.class_time == routine.class_time) || (m.class_id == routine.class_id && m.class_time == routine.class_time));

            if (data != null)
            {
                return(RedirectToAction(nameof(Create), new { msg = "Conflict" }));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    _context.Add(routine);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["class_id"]   = new SelectList(_context.Class, "id", "class_name", routine.class_id);
                ViewData["course_id"]  = new SelectList(_context.Course, "id", "course_code", routine.course_id);
                ViewData["teacher_id"] = new SelectList(_context.Teacher, "id", "name", routine.teacher_id);
                ViewData["year_id"]    = new SelectList(_context.Year, "id", "year_title", routine.year_id);
                return(View(routine));
            }
        }
Пример #2
0
        public async Task <IActionResult> Putdata(string id, data data)
        {
            if (id != data.Location)
            {
                return(BadRequest());
            }

            db.Entry(data).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!dataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Putaddress(int id, address address)
        {
            if (id != address.id)
            {
                return(BadRequest());
            }

            _context.Entry(address).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!addressExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #4
0
        public async Task <IActionResult> Putcostumer(int id, costumer costumer)
        {
            if (id != costumer.id)
            {
                return(BadRequest());
            }

            _context.Entry(costumer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!costumerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutPostInfo(int id, PostInfo postInfo)
        {
            if (id != postInfo.id)
            {
                return(BadRequest());
            }

            _context.Entry(postInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #6
0
        public async Task <IActionResult> AddUser([Bind("username,pass,type")] User logins)
        {
            if (ModelState.IsValid)
            {
                _context.Add(logins);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(logins));
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Fee_Id,F_Name")] Fees fees)
        {
            if (ModelState.IsValid)
            {
                _context.Add(fees);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(fees));
        }
Пример #8
0
        public async Task <IActionResult> Create([Bind("id,std_id,name,age,gender,Class,paid,due")] StudentInfo studentInfo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(studentInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(studentInfo));
        }
Пример #9
0
        public async Task <IActionResult> Create([Bind("id,class_name")] Class @class)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@class);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@class));
        }
Пример #10
0
        public async Task <IActionResult> Create([Bind("user_name,password,type")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Пример #11
0
        public async Task <IActionResult> Create([Bind("id,year_title,status")] Year year)
        {
            if (ModelState.IsValid)
            {
                _context.Add(year);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(year));
        }
Пример #12
0
        public async Task <IActionResult> Create([Bind("id,name,phone,address,user_name,password")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
Пример #13
0
        public async Task <IActionResult> Create([Bind("id,course_code,course_name,class_id")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["class_id"] = new SelectList(_context.Class, "id", "class_name", course.class_id);
            return(View(course));
        }
Пример #14
0
        public async Task <IActionResult> Create([Bind("Std_Id,Name,Birth_Date,Gender,Contact,Address,Father_Name,Mother_Name,Class,M_Id")] Students students)
        {
            if (ModelState.IsValid)
            {
                _context.Add(students);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["M_Id"] = new SelectList(_context.Months, "M_Id", "M_Name", students.M_Id);
            return(View(students));
        }
Пример #15
0
        public async Task <IActionResult> Create([Bind("id,name,phone,address,user_name,password,class_id,year_id")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["class_id"] = new SelectList(_context.Class, "id", "class_name", student.class_id);
            ViewData["year_id"]  = new SelectList(_context.Year, "id", "year_title", student.year_id);
            return(View(student));
        }
Пример #16
0
        public async Task <IActionResult> Create([Bind("id,Std_Id,Fee_Id,Amount,M_Id")] Payment payment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(payment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Fee_Id"] = new SelectList(_context.Fees, "Fee_Id", "F_Name", payment.Fee_Id);
            ViewData["M_Id"]   = new SelectList(_context.Months, "M_Id", "M_Name", payment.M_Id);
            ViewData["Std_Id"] = new SelectList(_context.Students, "Std_Id", "Std_Id", payment.Std_Id);
            return(View(payment));
        }
Пример #17
0
        public async Task <ActionResult <UserDto> > Register(RegisterDto newuser)
        {
            if (await UserExists(newuser.username))
            {
                return(BadRequest("Username is taken"));
            }

            using var hmac = new HMACSHA512();

            var user = new appUser
            {
                UserName     = newuser.username,
                PasswordSalt = hmac.Key,
                passwordHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(newuser.password))
            };

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(new UserDto
            {
                UserName = user.UserName,
                Token = _tokenService.CreateToken(user)
            });
        }
Пример #18
0
        public async Task <bool> updateStudent(Student student)
        {
            Student dbcoursetwo = await _courseprDbContext.Student
                                  .Where(m => m.id == student.id)
                                  .FirstOrDefaultAsync();

            //if(originalItem == null)
            //return false;

            dbcoursetwo.id = student.id;

            // dbcoursetwo.teacherId = chcourse.courseId;
            dbcoursetwo.name     = student.name;
            dbcoursetwo.email    = student.email;
            dbcoursetwo.image    = student.image;
            dbcoursetwo.password = student.password;


            return(await _courseprDbContext.SaveChangesAsync() > 0);
        }
        public async Task <IActionResult> PutuserAccounts(Guid id, userAccounts userAccounts)
        {
            var oldUser = _context.userAccounts.FirstOrDefault(x => x.id == id);

            if (id != userAccounts.id)
            {
                return(BadRequest());
            }
            if (userAccounts.password != null)
            {
                string hashedPassword = BCrypt.Net.BCrypt.HashPassword(userAccounts.password);
                userAccounts.password = hashedPassword;
            }
            else
            {
                userAccounts.password = oldUser.password;
            }



            try
            {
                oldUser.userName = userAccounts.userName;
                oldUser.email    = userAccounts.email;
                oldUser.password = userAccounts.password;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!userAccountsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> stdreg(Students model)
        {
            if (ModelState.IsValid)
            {
                Students lcl_student = new Students
                {
                    Id        = model.Id,
                    Firstname = model.Firstname,
                    Lastname  = model.Lastname,
                    Standard  = model.Standard,
                    Address   = model.Address,
                    Email     = model.Email,
                };
                _context.student.Add(lcl_student);
                await _context.SaveChangesAsync();

                ViewBag.Success = "Data has been successfully saved";
                return(View());
            }

            return(View(model));
        }
Пример #21
0
        public async Task <User> Register(User user, string password)
        {
            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            await _context.User.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
        public async Task <User> Register(User user, string password)
        {
            DateTime now = DateTime.UtcNow;

            byte[] passwordHash, passwordSalt;
            CreatePassWordHash(password, out passwordHash, out passwordSalt);
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            user.Role         = "normal";
            user.PhotoUrl     = "https://res.cloudinary.com/marcelcloud/image/upload/v1559818775/user.png.jpg";
            user.Created      = now;

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            return(user);
        }
Пример #23
0
#pragma warning disable 4014
        new public static void OnStart(DiscordClient discord, IConfiguration configuration)
        {
            var context = new dataContext();

            discord.MessageCreated += async(client, args) =>
            {
                Task.Run(async() =>
                {
                    if (!args.Message.Content.StartsWith("\\") &&  // Not escaped
                        context.Anonchannels.Any(c => c.Id == args.Channel.Id.ToString()) &&     // In an anon channel
                        !args.Author.IsBot &&     // Not a bot
                        !context.AnonBans.AsNoTracking().AsEnumerable().Any(u => u.User == args.Author.Id.ToString() &&     // AsNoTracking used to avoid cache
                                                                            u.Server == args.Guild.Id.ToString() &&
                                                                            (u.ExpiresAt == (ulong)0 || u.ExpiresAt > (ulong)DateTimeOffset.Now.ToUnixTimeSeconds()))) // Not anonbanned
                    {
                        if (args.Message.Attachments.Count == 0)
                        {
                            try { await args.Message.DeleteAsync(); } catch { }
                        }
                        // TODO: Work around rate limit here
                        var webhook = await args.Channel.CreateWebhookAsync("Anon");
                        var msg     = new DiscordWebhookBuilder().WithContent(args.Message.Content.CleanPings(args.Guild));
                        foreach (var attachment in args.Message.Attachments)
                        {
                            var fileStream = WebRequest.Create(attachment.ProxyUrl).GetResponse().GetResponseStream();
                            msg.AddFile(attachment.FileName, fileStream);
                        }
                        var anonMessage = await webhook.ExecuteAsync(msg);
                        await webhook.DeleteAsync();
                        try { await args.Message.DeleteAsync(); } catch { }
                        await context.Anonmessages.AddAsync(new Anonmessage
                        {
                            Id     = anonMessage.Id.ToString(),
                            Server = anonMessage.Channel.GuildId.ToString(),
                            User   = args.Author.Id.ToString()
                        });
                        await context.SaveChangesAsync();
                    }
                }
                         );
            };
        }
Пример #24
0
 public async Task <bool> SaveAll()
 {
     return(await _context.SaveChangesAsync() > 0);
 }
Пример #25
0
        private async void OnSave(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (IsEditing) //neu dang o che do chinh sua
                {
                    var categoryLogic = new CategoryLogic(_dbContext);
                    // Kiem tra them xoa sua
                    foreach (var category in ListCategoryBindProp)
                    {
                        switch (category.Status)
                        {
                        case Status.New:
                            var newCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName
                            };
                            await categoryLogic.CreateAsync(newCategory, false);

                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            var modCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName
                            };
                            await categoryLogic.UpdateAsync(modCategory, false);

                            break;

                        case Status.Deleted:
                            break;

                        default:
                            break;
                        }
                        MessagingCenter.Send(category, Messages.CATEGORY_MESSAGE);
                    }

                    foreach (var cate in _listDeleted)
                    {
                        cate.Status = Status.Deleted;
                        await categoryLogic.DeleteAsync(cate.Id, false);

                        MessagingCenter.Send(cate, Messages.CATEGORY_MESSAGE);
                    }
                    //neu co nhap category moi thi tao roi quay ve
                    if (!string.IsNullOrWhiteSpace(NewCategoryNameBindProp))
                    {
                        var newCate = new Category
                        {
                            Id           = Guid.NewGuid().ToString(),
                            CategoryName = NewCategoryNameBindProp,
                        };
                        var newVsCate = new VisualCategoryModel
                        {
                            Id           = newCate.Id,
                            CategoryName = newCate.CategoryName,
                            Status       = Status.New
                        };
                        await categoryLogic.CreateAsync(newCate, false);

                        ListCategoryBindProp.Add(newVsCate);
                        MessagingCenter.Send(newCate, Messages.CATEGORY_MESSAGE);
                    }

                    await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                    await NavigationService.GoBackAsync();
                }
                else // neu dang o che do binh thuong
                {
                    var categoryLogic = new CategoryLogic(_dbContext);
                    // Kiem tra them moi
                    foreach (var category in ListCategoryBindProp)
                    {
                        switch (category.Status)
                        {
                        case Status.New:
                            var newCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName,
                            };
                            await categoryLogic.CreateAsync(newCategory, false);

                            MessagingCenter.Send(category, Messages.CATEGORY_MESSAGE);
                            category.Status = Status.Normal;
                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            break;

                        case Status.Deleted:
                            break;
                        }
                    }

                    // neu khong nhap gi
                    if (string.IsNullOrWhiteSpace(NewCategoryNameBindProp))
                    {
                        //neu co chon thi tra ve ten category
                        if (SelectedCategoryBindProp != null)
                        {
                            //truyen ten category ve trang tao item
                            var param = new NavigationParameters();
                            param.Add(Keys.CATEGORY, SelectedCategoryBindProp);

                            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                            await NavigationService.GoBackAsync(param);
                        }
                        else
                        {
                            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                            return;
                        }
                    }
                    else // tao moi
                    {
                        var newCate = new Category
                        {
                            Id           = Guid.NewGuid().ToString(),
                            CategoryName = NewCategoryNameBindProp,
                        };
                        var newVsCate = new VisualCategoryModel
                        {
                            Id           = newCate.Id,
                            CategoryName = newCate.CategoryName,
                            Status       = Status.New
                        };
                        await categoryLogic.CreateAsync(newCate, false);

                        ListCategoryBindProp.Add(newVsCate);
                        MessagingCenter.Send(newCate, Messages.CATEGORY_MESSAGE);

                        await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                        //truyen ten category ve trang tao item
                        var param = new NavigationParameters();
                        param.Add(Keys.CATEGORY, newCate);

                        await NavigationService.GoBackAsync(param);
                    }
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Пример #26
0
        private async void OnCompeletePayment(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            if (ReceivedMoneyBindProp < BillBindProp.TotalPrice)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (!IsCompletedBindProp)
                {
                    IsCompletedBindProp = true;
                }
                else
                {
                    var invoiceLogic     = new InvoiceLogic(_dbContext);
                    var invoiceItemLogic = new InvoiceItemLogic(_dbContext);
                    var tableLogic       = new TableLogic(_dbContext);
                    var subItemLogic     = new ItemDiscountLogic(_dbContext);
                    var itemLogic        = new ItemLogic(_dbContext);

                    var invoice = new Invoice
                    {
                        Id            = BillBindProp.Id,
                        Status        = (int)InvoiceStatus.Paid,
                        PaidAmount    = ReceivedMoneyBindProp,
                        Tip           = TipBindProp,
                        TotalPrice    = BillBindProp.TotalPrice,
                        IsTakeAway    = BillBindProp.IsTakeAway,
                        FkTable       = BillBindProp.FkTable,
                        CloseDate     = DateTime.Now.ToString(),
                        CustomerCount = BillBindProp.CustomerCount,
                        InvoiceNumber = await GenerateInvoiceNumber()
                    };

                    if (IsEditing)
                    {
                        await invoiceLogic.UpdateAsync(invoice, false);
                    }
                    else
                    {
                        await invoiceLogic.CreateAsync(invoice, false);
                    }

                    if (BillBindProp.IsTakeAway == 0)
                    {
                        await tableLogic.ChangeStatusAsync(new Table
                        {
                            Id         = BillBindProp.FkTable,
                            IsSelected = 0
                        }, false);
                    }

                    foreach (var item in BillBindProp.ListItemInBill)
                    {
                        if (item.Status == Status.New)
                        {
                            await invoiceItemLogic.CreateAsync(new InvoiceItemOrDiscount
                            {
                                FkInvoice        = invoice.Id,
                                FkItemOrDiscount = item.Id,
                                Quantity         = item.Quantity,
                                IsDiscount       = 0,
                                Value            = item.Value
                            }, false);

                            for (int i = 1; i < item.ListSubItem.Count; i++)
                            {
                                await subItemLogic.CreateAsync(new ItemDiscount
                                {
                                    FkItem     = item.Id,
                                    FkDiscount = item.ListSubItem[i].Id,
                                    Value      = item.ListSubItem[i].Value
                                }, false);
                            }
                        }
                        await itemLogic.ModifyQuantityAsync(item.Id, -item.Quantity, false);
                    }

                    foreach (var item in BillBindProp.ListDiscount)
                    {
                        if (item.Status == Status.New)
                        {
                            await invoiceItemLogic.CreateAsync(new InvoiceItemOrDiscount
                            {
                                FkInvoice        = invoice.Id,
                                FkItemOrDiscount = item.Id,
                                Quantity         = item.Quantity,
                                IsDiscount       = 1,
                                Value            = item.Value
                            }, false);
                        }
                    }

                    await _dbContext.SaveChangesAsync();

                    var param = new NavigationParameters();
                    param.Add(Keys.BILL, BillBindProp.Id);
                    await NavigationService.GoBackAsync(param);
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Пример #27
0
        private async void OnSave(object obj)
        {
            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var tableLogic = new TableLogic(_dbContext);
                var zoneLogic  = new ZoneLogic(_dbContext);
                var zone       = new Zone();
                //Neu chinh sua
                if (IsEditing)
                {
                    zone.Id       = ZoneBindProp.Id;
                    zone.ZoneName = ZoneBindProp.ZoneName;

                    await zoneLogic.UpdateAsync(zone, false);

                    foreach (var table in ListTableBindProp)
                    {
                        switch (table.Status)
                        {
                        case Status.New:
                            await tableLogic.CreateAsync(new Table
                            {
                                Id        = Guid.NewGuid().ToString(),
                                FkZone    = table.FkZone,
                                TableName = table.TableName,
                                TableSize = (int)table.TableSize,
                                TableType = (int)table.TableType
                            }, false);

                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            await tableLogic.UpdateAsync(new Table
                            {
                                Id        = table.Id,
                                TableName = table.TableName,
                                TableSize = (int)table.TableSize,
                                TableType = (int)table.TableType
                            }, false);

                            break;

                        case Status.Deleted:
                            break;

                        default:
                            break;
                        }
                    }

                    foreach (var table in _listDeletedTable)
                    {
                        await tableLogic.DeleteAsync(table.Id, false);
                    }

                    await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                    //gui thong tin den trang chu
                    MessagingCenter.Send(ZoneBindProp, Messages.ZONE_MESSAGE);
                    MessagingCenter.Send(ListTableBindProp, Messages.TABLE_MESSAGE);

                    await NavigationService.GoBackAsync();
                }
                else // tao moi
                {
                    zone = await zoneLogic.CreateAsync(new Zone
                    {
                        Id       = ZoneBindProp.Id,
                        ZoneName = ZoneBindProp.ZoneName,
                    }, false);

                    foreach (var table in ListTableBindProp)
                    {
                        switch (table.Status)
                        {
                        case Status.New:
                            await tableLogic.CreateAsync(new Table
                            {
                                Id        = Guid.NewGuid().ToString(),
                                FkZone    = table.FkZone,
                                TableName = table.TableName,
                                TableSize = (int)table.TableSize,
                                TableType = (int)table.TableType
                            }, false);

                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            await tableLogic.CreateAsync(new Table
                            {
                                Id        = Guid.NewGuid().ToString(),
                                FkZone    = table.FkZone,
                                TableName = table.TableName,
                                TableSize = (int)table.TableSize,
                                TableType = (int)table.TableType
                            }, false);

                            break;

                        case Status.Deleted:
                            break;

                        default:
                            break;
                        }
                    }

                    await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                    //gui thong tin den trang chu
                    MessagingCenter.Send(ZoneBindProp, Messages.ZONE_MESSAGE);
                    MessagingCenter.Send(ListTableBindProp, Messages.TABLE_MESSAGE);

                    var param = new NavigationParameters();
                    param.Add(Keys.ZONE, ZoneBindProp);

                    await NavigationService.GoBackAsync(param);
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }