Exemple #1
0
 public IActionResult Create(Contact contact)
 {
     if (ModelState.IsValid)
     {
         _context.Contacts.Add(contact);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(contact));
 }
Exemple #2
0
        public ActionResult Create([Bind(Include = "PersonId,LastName,FirstName,BirthDate")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.Persons.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
        public ActionResult Create([Bind(Include = "ArticleId,ColumnId,Hits,Title,Keywords,Author,Pictures,Content,Authorized,PublishTime,ReviseTime")] Article article)
        {
            if (ModelState.IsValid)
            {
                db.Articles.Add(article);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(article));
        }
Exemple #4
0
        public ActionResult Create([Bind(Include = "Id,CodeName,Name")] Permission permission)
        {
            if (ModelState.IsValid)
            {
                db.Permissions.Add(permission);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(permission));
        }
Exemple #5
0
        public ActionResult Create([Bind(Include = "Id,Name")] Role role)// tao moi 1 role
        {
            if (ModelState.IsValid)
            {
                db.Roles.Add(role);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(role));
        }
Exemple #6
0
        public ActionResult Create([Bind(Include = "Id,Name,UserId")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "Id", "Username", product.UserId);
            return(View(product));
        }
Exemple #7
0
        public ActionResult Create([Bind(Include = "Id,Username,Password,Email,SecurityPassword,ActivationCode,TimeGetCode,CountLogin,TimeCountLogin,ConfirmActivity")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Exemple #8
0
 public ActionResult Register([Bind(Include = "Username,Password,RPassword,Email")] User account)
 {
     try
     {
         //var vali = valid.ValidUserName(account.Username);
         //if (vali != "")
         //    ModelState.AddModelError("UserName", vali);
         //vali = valid.ValidEmail(account.Email);
         //if (vali != "")
         //    ModelState.AddModelError("Email", vali);
         //vali = valid.ValidatePassword(account.Password);
         //if (vali != "")
         //    ModelState.AddModelError("Password", vali);
         //vali = valid.ValidatePassword(account.RPassword);
         //if (vali != "")
         //    ModelState.AddModelError("RPassword", vali);
         if (account.Password != null && !account.Password.Equals(account.RPassword))
         {
             ModelState.AddModelError("RPassword", "Xác nhận mật khẩu không đúng.");
         }
         if (ModelState.IsValid)
         {
             //Gui mail xac nhan email dang ky
             Guid activationCode = Guid.NewGuid();
             if (email.SendMailAccount(account.Username, account.Email, activationCode.ToString()))
             {
                 account.ActivationCode = activationCode.ToString();
                 account.TimeGetCode    = DateTime.UtcNow;
                 account.Password       = encode.EncodeMd(account.Password);
                 db.Users.Add(account);
                 db.SaveChanges();
                 account.Password  = null;
                 account.RPassword = null;
                 ViewBag.Message   = "Đăng ký thành công. Mã xác nhận đã được gửi đến email của bạn.";
             }
         }
     }
     catch (DbEntityValidationException dbEx)
     {
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 System.Console.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             }
         }
     }
     return(View(account));
 }
Exemple #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                expenseItem.ExpenseCategoryId = (int)cmbCategory.SelectedValue;
                expenseItem.Name = txtName.Text;
                if (txtCodeManual.Text.Trim() != String.Empty)
                {
                    expenseItem.Code = txtCodeManual.Text;
                }
                else
                {
                    expenseItem.Code = txtCode.Text;
                }

                expenseItem.Description = txtDescription.Text;

                db.ExpenseItems.Add(expenseItem);
                int count = db.SaveChanges();
                if (count > 0)
                {
                    MessageBox.Show("Successfully Item Saved");
                }
                else
                {
                    MessageBox.Show("Failed Insertion");
                }
                ClearAllTextBox();
                LoadDataGridViewItem();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + "Please fill text box!");
            }
        }
        public IActionResult SignUp(UserDTO user)
        {
            //check if username exists
            if (_ctx.Credentials.Find(user.Username) != null)
            {
                return(new BadRequestObjectResult("Username already exists"));
            }

            //check if email formatted right
            if (!ValidMail(user.Email))
            {
                return(new BadRequestObjectResult("That's not an email"));
            }

            //check if mail exists
            if (_ctx.Users.SingleOrDefault(u => u.Email == user.Email) != null)
            {
                return(new BadRequestObjectResult("Email already exists"));
            }

            var newUser = CreateUser(user);

            _ctx.Users.Add(newUser);
            _ctx.SaveChanges();


            var jwtToken = GenerateAccessToken(user.Email, user.Username);

            Response.Headers.Add("Authentication", jwtToken);
            user.Password = "";

            return(Ok(user));
        }
Exemple #11
0
        private void EditManager()
        {
            using (ManagerContext context = new ManagerContext())
            {
                //фиксируем менеджера
                context.Managers.Attach(manager);

                manager.Credential  = credential;
                manager.Person.Info = info;
                if (radioButtonMan.Checked)
                {
                    manager.Person.Sex = true;
                }
                else
                {
                    manager.Person.Sex = false;
                }
                manager.Person.ICNumber             = textBoxICNumber.Text.Trim();
                manager.Person.ICGettingPlace       = textBoxICGettingPlace.Text.Trim();
                manager.Person.PassportGettingPlace = textBoxPassportGettingPlace.Text.Trim();
                manager.Person.PassportNumber       = textBoxPassportNumber.Text.Trim();
                manager.Person.IIN        = textBoxIIN.Text.Trim();
                manager.Person.LastName   = textBoxLastName.Text.Trim();
                manager.Person.SecondName = textBoxSecondName.Text.Trim();
                manager.Person.FirstName  = textBoxFirstName.Text.Trim();

                //manager info date
                manager.Person.Birthday           = dateTimePickerBirthDay.Value;
                manager.Person.ICGettingDay       = dateTimePickerICGettingDate.Value;
                manager.Person.PassportGettingDay = dateTimePickerPassportGettingDate.Value;
                //сохраняем данные
                context.Entry(manager).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
Exemple #12
0
        private void AddManager()
        {
            using (ManagerContext context = new ManagerContext())
            {
                manager.Credential  = credential;
                manager.Person.Info = info;
                if (radioButtonMan.Checked)
                {
                    manager.Person.Sex = true;
                }
                else
                {
                    manager.Person.Sex = false;
                }
                manager.Person.ICNumber             = textBoxICNumber.Text.Trim();
                manager.Person.ICGettingPlace       = textBoxICGettingPlace.Text.Trim();
                manager.Person.PassportGettingPlace = textBoxPassportGettingPlace.Text.Trim();
                manager.Person.PassportNumber       = textBoxPassportNumber.Text.Trim();
                manager.Person.IIN        = textBoxIIN.Text.Trim();
                manager.Person.LastName   = textBoxLastName.Text.Trim();
                manager.Person.SecondName = textBoxSecondName.Text.Trim();
                manager.Person.FirstName  = textBoxFirstName.Text.Trim();

                //manager info date
                manager.Person.Birthday           = dateTimePickerBirthDay.Value;
                manager.Person.ICGettingDay       = dateTimePickerICGettingDate.Value;
                manager.Person.PassportGettingDay = dateTimePickerPassportGettingDate.Value;
                //сохраняем данные
                context.Managers.Add(manager);
                context.SaveChanges();
            }
        }
Exemple #13
0
        private void dgvPurchaseReport_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvPurchaseReport.CurrentCell.ColumnIndex.Equals(7))
            {
                if (dgvPurchaseReport.CurrentCell != null && dgvPurchaseReport.CurrentCell.Value != null)
                {
                    if (dgvPurchaseReport.CurrentRow != null)
                    {
                        int id = (int)dgvPurchaseReport.CurrentRow.Cells[0].Value;

                        using (ManagerContext db = new ManagerContext())
                        {
                            var purchaseId = db.Purchases.FirstOrDefault(c => c.Id == id);;
                            if (purchaseId != null)
                            {
                                purchaseId.IsDelete = true;
                                int count = db.SaveChanges();
                                if (count > 0)
                                {
                                    MessageBox.Show("Successfully Deleted");
                                }
                                else
                                {
                                    MessageBox.Show("Operation Failed");
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #14
0
        private void AddMITCast(ManagerContext aContext)
        {
            List <Person> vPersonList = new List <Person>
            {
                new Person {
                    FirstName = "Cary", LastName = "Elwes", BirthDate = new DateTime(1962, 10, 26)
                },
                new Person {
                    FirstName = "Richard", LastName = "Lewis", BirthDate = new DateTime(1947, 6, 29)
                },
                new Person {
                    FirstName = "Roger", LastName = "Rees", BirthDate = new DateTime(1944, 5, 5)
                },
                new Person {
                    FirstName = "Amy", LastName = "Yasbeck", BirthDate = new DateTime(1962, 9, 12)
                },
                new Person {
                    FirstName = "Mark", LastName = "Blankfield", BirthDate = new DateTime(1950, 5, 8)
                },
                new Person {
                    FirstName = "Dave", LastName = "Chappelle", BirthDate = new DateTime(1973, 8, 24)
                },
                new Person {
                    FirstName = "Megan", LastName = "Cavanagh", BirthDate = new DateTime(1960, 11, 8)
                },
                new Person {
                    FirstName = "Eric", LastName = "Kramer", BirthDate = new DateTime(1962, 3, 26)
                },
                new Person {
                    FirstName = "Matthew", LastName = "Porrette", BirthDate = new DateTime(1965, 5, 29)
                },
                new Person {
                    FirstName = "Tracey", LastName = "Ullman", BirthDate = new DateTime(1959, 12, 30)
                },
            };
            List <Employee> vEmployeeList = new List <Employee>();

            foreach (Person vPerson in vPersonList)
            {
                aContext.Persons.AddOrUpdate(
                    person => person.LastName,
                    vPerson
                    );
                vEmployeeList.Add(
                    new Employee {
                    EmployeeNum = (vPersonList.IndexOf(vPerson) + 1).ToString(), EmployedDate = new DateTime(1993, 1, 1), TerminatedDate = new DateTime(1999, 1, 1), Person = vPerson
                }
                    );
            }

            foreach (Employee vEmployee in vEmployeeList)
            {
                aContext.Employees.AddOrUpdate(
                    emp => emp.PersonId,
                    vEmployee
                    );
            }

            aContext.SaveChanges();
        }
Exemple #15
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("Do you want to Save", "Confirmation",
                                                      MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (result == DialogResult.Yes)
                {
                    expense.ExpenseList    = expenseLists;
                    expense.InvoiceNo      = SetInvioceNo();
                    expense.Remarks        = txtRemark.Text;
                    expense.TotalAmount    = Convert.ToDecimal(txtTotalShow.Text);
                    expense.OrganizationId = (int)cmbOrganization.SelectedValue;
                    expense.OutletId       = (int)cmbOutlet.SelectedValue;
                    expense.EmployeeId     = (int)cmbEmployee.SelectedValue;
                    expense.Date           = dateTimePicker.Value;

                    db.Expenses.Add(expense);
                    int count = db.SaveChanges();
                    MessageBox.Show(count > 0 ? "Expense save successfully!" : "Save failed");
                }
                else if (result == DialogResult.No)
                {
                    MessageBox.Show("You have clicked Cancel Button");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            ClearTextBoxAll();
        }
Exemple #16
0
        private void SaveStock()
        {
            try
            {
                using (ManagerContext db = new ManagerContext())
                {
                    foreach (Stock itemId in listofstock)
                    {
                        List <TempPurchase> listofTemp = db.TempPurchases.Where(a => a.ItemId == itemId.ItemId).ToList();

                        decimal avg             = listofTemp.Sum(a => a.TotalPrice) / listofTemp.Sum(a => a.Quantity);
                        var     isAvailableItem = db.Stocks.FirstOrDefault(a => a.ItemId == itemId.ItemId);
                        var     quantity        = itemId.AvailableQuantity;

                        if (isAvailableItem != null)
                        {
                            isAvailableItem.AvailableQuantity += itemId.AvailableQuantity;
                            isAvailableItem.AveragePrice       = avg;
                        }
                        else
                        {
                            db.Stocks.AddRange(listofstock);
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnSave_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (!isUpdateMode)
                {
                    GetTextBoxValue();


                    db.CustomerAndSuppliers.Add(customerAndSupplier);
                    int count = db.SaveChanges();
                    if (count > 0)
                    {
                        MessageBox.Show("Successfully Saved");
                    }
                    else
                    {
                        MessageBox.Show("Save failed");
                    }
                }


                if (isUpdateMode)
                {
                    GetTextBoxValue();
                    db.CustomerAndSuppliers.Attach(customerAndSupplier);
                    db.Entry(customerAndSupplier).State = System.Data.Entity.EntityState.Modified;
                    int count = db.SaveChanges();
                    if (count > 0)
                    {
                        MessageBox.Show("Successfully Updated");
                    }
                    else
                    {
                        MessageBox.Show("Update failed");
                    }
                }

                LoadDataGridView();

                ClearAllTextBox();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + "Please fill text box!");
            }
        }
Exemple #18
0
 public IActionResult Create(WebManageUsers user)
 {
     user.AddTime = DateTime.Now;
     user.Mobile  = string.Empty;
     _context.WebManageUsers.Add(user);
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public ActionResult DeleteConfirmed(int id)
        {
            Employee employee = db.Employees.Find(id);

            db.Employees.Remove(employee);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #20
0
 /* Добавление студента с первоначальными данными */
 public void AddPotentialStudent(Student student)
 {
     using (var db = new ManagerContext())
     {
         db.Students.Add(student);
         db.SaveChanges();
     }
 }
        public static void AddEmployee(
            ManagerContext aDbContext,
            Employee aNewEmployee
            )
        {
            aDbContext.Employees.Add(aNewEmployee);

            aDbContext.SaveChanges();
        }
 public static Employee EditEmployee(
     ManagerContext aDbContext,
     Employee aNewEmployee
     )
 {
     aDbContext.Entry(aNewEmployee).State = EntityState.Modified;
     aDbContext.SaveChanges();
     return(aNewEmployee);
 }
Exemple #23
0
        private void AddTNGCast(ManagerContext aContext)
        {
            List <Person> vPersonList = new List <Person>
            {
                new Person {
                    FirstName = "Patrick", LastName = "Stewart", BirthDate = new DateTime(1940, 7, 13)
                },
                new Person {
                    FirstName = "Jonathan", LastName = "Frakes", BirthDate = new DateTime(1952, 8, 19)
                },
                new Person {
                    FirstName = "LeVar", LastName = "Burton", BirthDate = new DateTime(1957, 2, 16)
                },
                new Person {
                    FirstName = "Marina", LastName = "Sirtis", BirthDate = new DateTime(1955, 3, 29)
                },
                new Person {
                    FirstName = "Brent", LastName = "Spiner", BirthDate = new DateTime(1949, 2, 2)
                },
                new Person {
                    FirstName = "Michael", LastName = "Dorn", BirthDate = new DateTime(1952, 12, 9)
                },
                new Person {
                    FirstName = "Gates", LastName = "McFadden", BirthDate = new DateTime(1949, 3, 2)
                },
                new Person {
                    FirstName = "Majel", LastName = "Barrett", BirthDate = new DateTime(1949, 3, 2)
                },
            };
            List <Employee> vEmployeeList = new List <Employee>();

            foreach (Person vPerson in vPersonList)
            {
                aContext.Persons.AddOrUpdate(
                    person => person.LastName,
                    vPerson
                    );
                vEmployeeList.Add(
                    new Employee {
                    EmployeeNum = (vPersonList.IndexOf(vPerson) + 1).ToString(), EmployedDate = new DateTime(1987, 1, 1), TerminatedDate = new DateTime(1994, 1, 1), Person = vPerson
                }
                    );
            }

            foreach (Employee vEmployee in vEmployeeList)
            {
                aContext.Employees.AddOrUpdate(
                    emp => emp.PersonId,
                    vEmployee
                    );
            }

            aContext.SaveChanges();
        }
 /// <summary>
 /// Saves the changes made to the database.
 /// </summary>
 /// <returns>An integer that represents whether the changes saved successfully.</returns>
 public int Complete()
 {
     try
     {
         return(context.SaveChanges());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #25
0
        private void AddDS9Cast(ManagerContext aContext)
        {
            List <Person> vPersonList = new List <Person>
            {
                new Person {
                    FirstName = "Avery", LastName = "Brooks", BirthDate = new DateTime(1948, 10, 2)
                },
                new Person {
                    FirstName = "Rene", LastName = "Auberjonois", BirthDate = new DateTime(1940, 6, 1)
                },
                new Person {
                    FirstName = "Cirroc", LastName = "Lofton", BirthDate = new DateTime(1978, 8, 7)
                },
                new Person {
                    FirstName = "Alexander", LastName = "Siddig", BirthDate = new DateTime(1965, 11, 21)
                },
                new Person {
                    FirstName = "Colm", LastName = "Meaney", BirthDate = new DateTime(1953, 5, 30)
                },
                new Person {
                    FirstName = "Nana", LastName = "Visitor", BirthDate = new DateTime(1957, 7, 26)
                },
                new Person {
                    FirstName = "Armin", LastName = "Shimerman", BirthDate = new DateTime(1949, 11, 5)
                },
                new Person {
                    FirstName = "Terry", LastName = "Farrell", BirthDate = new DateTime(1963, 11, 19)
                },
            };
            List <Employee> vEmployeeList = new List <Employee>();

            foreach (Person vPerson in vPersonList)
            {
                aContext.Persons.AddOrUpdate(
                    person => person.LastName,
                    vPerson
                    );
                vEmployeeList.Add(
                    new Employee {
                    EmployeeNum = (vPersonList.IndexOf(vPerson) + 1).ToString(), EmployedDate = new DateTime(1993, 1, 1), TerminatedDate = new DateTime(1999, 1, 1), Person = vPerson
                }
                    );
            }

            foreach (Employee vEmployee in vEmployeeList)
            {
                aContext.Employees.AddOrUpdate(
                    emp => emp.PersonId,
                    vEmployee
                    );
            }

            aContext.SaveChanges();
        }
Exemple #26
0
        private void AddOriginalSeriesCast(ManagerContext aContext)
        {
            List <Person> vPersonList = new List <Person>
            {
                new Person {
                    FirstName = "Leonard", LastName = "Nimoy", BirthDate = new DateTime(1932, 4, 26)
                },
                new Person {
                    FirstName = "William", LastName = "Shatner", BirthDate = new DateTime(1931, 3, 22)
                },
                new Person {
                    FirstName = "DeForest", LastName = "Kelley", BirthDate = new DateTime(1920, 1, 20)
                },
                new Person {
                    FirstName = "Nichelle", LastName = "Nichols", BirthDate = new DateTime(1932, 12, 28)
                },
                new Person {
                    FirstName = "James", LastName = "Doohan", BirthDate = new DateTime(1920, 3, 3)
                },
                new Person {
                    FirstName = "George", LastName = "Takei", BirthDate = new DateTime(1937, 4, 20)
                },
                new Person {
                    FirstName = "Walter", LastName = "Koenig", BirthDate = new DateTime(1936, 9, 14)
                },
            };
            List <Employee> vEmployeeList = new List <Employee>();

            foreach (Person vPerson in vPersonList)
            {
                aContext.Persons.AddOrUpdate(
                    person => person.LastName,
                    vPerson
                    );
                vEmployeeList.Add(
                    new Employee {
                    EmployeeNum = (vPersonList.IndexOf(vPerson) + 1).ToString(), EmployedDate = new DateTime(1966, 1, 1), TerminatedDate = new DateTime(1969, 1, 1), Person = vPerson
                }
                    );
            }

            foreach (Employee vEmployee in vEmployeeList)
            {
                aContext.Employees.AddOrUpdate(
                    emp => emp.PersonId,
                    vEmployee
                    );
            }

            aContext.SaveChanges();
        }
Exemple #27
0
 protected override void OnStartup(StartupEventArgs e)
 {
     try
     {
         if (!_context.Passwords.Any())
         {
             _context.Passwords.Add(new Models.RootPassword
             {
                 Password = DbManager.Properties.Settings.Default.defaultPassword
             });
             _context.SaveChanges();
         }
     }
     catch (System.Exception)
     {
         OnStartup(e);
     }
 }
Exemple #28
0
 private void UpdateStock()
 {
     try
     {
         Stock stock = new Stock();
         stock.ItemId            = (int)listOfSalesItem[0].ItemId;
         stock.AvailableQuantity = listOfSalesItem[0].Quantity;
         using (ManagerContext db = new ManagerContext())
         {
             db.Stocks.Attach(stock);
             db.Entry(stock).Property(X => X.AvailableQuantity).IsModified = true;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemple #29
0
        public IActionResult CreateTask(int id, SharedTasks task)
        {
            string username = HttpContext.User.Identity.Name;

            var group = _ctx.Groups
                        .Include(g => g.SharedTasks)
                        .FirstOrDefault(g => g.GroupId == id);

            if (group == null || group.AdminUsername != username)
            {
                return(Unauthorized());
            }

            task.GroupId = id;
            _ctx.SharedTasks.Add(task);

            _ctx.SaveChanges();

            return(Ok(task));
        }
Exemple #30
0
        public IActionResult DeleteMember(int groupId, string memberUsername)
        {
            string username = HttpContext.User.Identity.Name;

            if (!AdminIsValid(username, groupId))
            {
                return(Unauthorized());
            }

            var member = _ctx.Memberships.Find(memberUsername, groupId);

            if (member == null)
            {
                return(NotFound());
            }

            _ctx.Memberships.Remove(member);
            _ctx.SaveChanges();

            return(NoContent());
        }