public async Task <IActionResult> CreatePrivateTask(PrivateTask task)
        {
            PrivateTask newTask = new PrivateTask()
            {
                Title       = task.Title,
                Deadline    = task.Deadline,
                Description = task.Description,
                Checklists  = task.Checklists,
                Status      = task.Status
            };

            var username = HttpContext.User.Identity.Name;

            var user = await _ctx.Credentials
                       .SingleOrDefaultAsync(u => u.Username == username);

            _ctx.Entry(user)
            .Collection(u => u.PrivateTasks)
            .Load();

            if (!user.PrivateTasks.Any())
            {
                user.PrivateTasks = new List <PrivateTask>();
            }

            user.PrivateTasks.Add(newTask);

            await _ctx.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetAPrivateTask), new { id = newTask.TaskId }, newTask));
        }
 public async Task <IHttpActionResult> Put([FromODataUri] Guid key, Manager update)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     if (key != update.Id)
     {
         return(BadRequest());
     }
     db.Entry(update).State = EntityState.Modified;
     try
     {
         await db.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!ManagerExists(key))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(Updated(update));
 }
Exemplo n.º 3
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();
            }
        }
Exemplo n.º 4
0
        public virtual async Task <T> Update(T obj)
        {
            _context.Entry(obj).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(obj);
        }
Exemplo n.º 5
0
        public async Task <IActionResult> DeleteConfirmed(Guid id)
        {
            var address = await _context.Address.FindAsync(id);

            _context.Entry(address).State = EntityState.Deleted;
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 6
0
 public static Employee EditEmployee(
     ManagerContext aDbContext,
     Employee aNewEmployee
     )
 {
     aDbContext.Entry(aNewEmployee).State = EntityState.Modified;
     aDbContext.SaveChanges();
     return(aNewEmployee);
 }
Exemplo n.º 7
0
 public ActionResult Edit([Bind(Include = "Id,CodeName,Name")] Permission permission)
 {
     if (ModelState.IsValid)
     {
         db.Entry(permission).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(permission));
 }
Exemplo n.º 8
0
 public ActionResult Edit([Bind(Include = "Id,Name")] Role role)
 {
     if (ModelState.IsValid)
     {
         db.Entry(role).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(role));
 }
Exemplo n.º 9
0
 public ActionResult Edit([Bind(Include = "ArticleId,ColumnId,Hits,Title,Keywords,Author,Pictures,Content,Authorized,PublishTime,ReviseTime")] Article article)
 {
     if (ModelState.IsValid)
     {
         db.Entry(article).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(article));
 }
Exemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "Id,Username,Password,Email,SecurityPassword,ActivationCode,TimeGetCode,CountLogin,TimeCountLogin,ConfirmActivity")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Exemplo n.º 11
0
 public ActionResult Edit([Bind(Include = "PersonId,LastName,FirstName,BirthDate")] Person person)
 {
     if (ModelState.IsValid)
     {
         db.Entry(person).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(person));
 }
Exemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "Id,Name,UserId")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserId = new SelectList(db.Users, "Id", "Username", product.UserId);
     return(View(product));
 }
Exemplo n.º 13
0
        public async Task <IActionResult> DeleteConfirmed(Guid id)
        {
            try
            {
                var user = await _context.User.FindAsync(id);

                _context.Entry(user).State = EntityState.Deleted;
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException)
            {
                return(RedirectToAction(nameof(Delete), new { id = id, saveChangesError = true }));
            }
        }
Exemplo n.º 14
0
        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!");
            }
        }
Exemplo n.º 15
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);
     }
 }
Exemplo n.º 16
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Title,Description,Creator,CreationDate")] Topic topic)
        {
            if (id != topic.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var model = await _context.Topics.FindAsync(topic.Id);

                    topic.CreationDate = model.CreationDate;
                    topic.Creator      = model.Creator;

                    _context.Entry(model).CurrentValues.SetValues(topic);
                    //_context.Update(topic);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TopicExists(topic.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Creator"] = new SelectList(_context.Users, "Id", "Id", topic.Creator);
            return(View(topic));
        }
Exemplo n.º 17
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtOranizationName.Text.Trim() == string.Empty && txtContactNo.Text.Trim() == string.Empty && txtAddress.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please fill text box !");
                return;
            }
            int  no;
            bool isInteger = int.TryParse(txtContactNo.Text.Trim(), out no);

            if (!isInteger)
            {
                MessageBox.Show("Mobile no invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtContactNo.Clear();
                return;
            }

            try
            {
                if (!_isUpdateMode)
                {
                    TextBoxValue();

                    bool isContactNoExist = db.Organizations.Count(c => c.ContactNo == org.ContactNo) > 0;
                    if (isContactNoExist)
                    {
                        MessageBox.Show("Contact No Allready Exist");
                        return;
                    }
                    DialogResult dialogResult = MessageBox.Show("Are you sure want to save ?", "Information", MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        db.Organizations.Add(org);
                        int result = db.SaveChanges();
                        if (result > 0)
                        {
                            MessageBox.Show("Organization saved Successfully");
                        }
                        else
                        {
                            MessageBox.Show("Save failed");
                        }
                    }
                }

                if (_isUpdateMode)
                {
                    TextBoxValue();
                    bool isContactNoExist = db.Organizations.Count(c => c.ContactNo == org.ContactNo) > 1;
                    if (isContactNoExist)
                    {
                        MessageBox.Show("Contact No Allready Exist");
                        return;
                    }
                    DialogResult dialogResult = MessageBox.Show("Are you sure want to update ?", "Information", MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        db.Organizations.Attach(org);
                        db.Entry(org).State = EntityState.Modified;
                        int count = db.SaveChanges();
                        if (count > 0)
                        {
                            MessageBox.Show("Organization updated");
                        }
                        else
                        {
                            MessageBox.Show("Update failed");
                        }
                    }
                }

                LoadDataGridView();
                ClearTextBoxAll();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " \n" + " Find system error! ", MessageBoxIcon.Warning.ToString());
            }
        }
Exemplo n.º 18
0
        private void btnSave_Click_1(object sender, EventArgs e)
        {
            try
            {
                if (!isUpdateMode)
                {
                    TextBoxValue();
                    bool isExistContactNo = db.Employees.Count(c => c.ContactNo == aEmployee.ContactNo) > 0;
                    bool isMailExist      = db.Employees.Count(mail => mail.Email == aEmployee.Email) > 0;
                    if (isExistContactNo)
                    {
                        MessageBox.Show("Contact no already exist");
                        return;
                    }

                    if (isMailExist)
                    {
                        MessageBox.Show("Email Id already Exist");
                        return;
                    }
                    DialogResult dialogResult = MessageBox.Show("Are you sure want to Save ?", "Information", MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        db.Employees.Add(aEmployee);
                        int count = db.SaveChanges();
                        if (count > 0)
                        {
                            MessageBox.Show("Employee Save");
                        }
                        else
                        {
                            MessageBox.Show(" Save Failed");
                        }
                    }
                }
                if (isUpdateMode)
                {
                    DialogResult dialogResult = MessageBox.Show("Are you sure want to update ?", "Information", MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        TextBoxValue();
                        db.Employees.Attach(aEmployee);
                        db.Entry(aEmployee).State = EntityState.Modified;
                        int count = db.SaveChanges();
                        if (count > 0)
                        {
                            MessageBox.Show("Employee updated");
                        }
                        else
                        {
                            MessageBox.Show(" Update Failed");
                        }
                    }
                }

                LoadDataGridView();
                ClearTextBoxAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + "Pleas fill taxt box!");
            }
        }
Exemplo n.º 19
0
        private void btnSaveCategory_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim() == string.Empty && txtDescription.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please fill text box !");
                return;
            }
            try
            {
                if (!_isUpdateMode)
                {
                    try
                    {
                        if (rbRootCategory.Checked)
                        {
                            itemCategory.Name = txtName.Text;
                            if (txtCodeManual.Text.Trim() != string.Empty)
                            {
                                itemCategory.Code = txtCodeManual.Text;
                            }
                            else
                            {
                                itemCategory.Code = txtCode.Text;
                            }
                            itemCategory.Description = txtDescription.Text;

                            db.ItemCategories.Add(itemCategory);
                            int count = db.SaveChanges();
                            if (count > 0)
                            {
                                MessageBox.Show("Root Category saved!");
                            }
                            else
                            {
                                MessageBox.Show("Save failed!");
                            }
                        }
                        else if (rbSubCategory.Checked)
                        {
                            VisibleRootCategory();
                            itemCategory.CategoryId = (int)cmbRootCategory.SelectedValue;
                            itemCategory.Name       = txtName.Text;
                            if (txtCodeManual.Text.Trim() != string.Empty)
                            {
                                itemCategory.Code = txtCodeManual.Text;
                            }
                            else
                            {
                                itemCategory.Code = txtCode.Text;
                            }
                            itemCategory.Description = txtDescription.Text;

                            DialogResult dialogResult = MessageBox.Show("Are you sure want to save ?", "Information",
                                                                        MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            if (dialogResult == DialogResult.Yes)
                            {
                                db.ItemCategories.Add(itemCategory);
                                int count = db.SaveChanges();
                                if (count > 0)
                                {
                                    MessageBox.Show("Sub Category saved!");
                                }
                                else
                                {
                                    MessageBox.Show("Save failed!");
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Please Select Category!");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + " \n" + "[NB] Operating system found error!");
                    }
                }

                if (_isUpdateMode)
                {
                    TextBoxValue();

                    if (rbRootCategory.Checked)
                    {
                        itemCategory.CategoryId = null;
                        itemCategory.Name       = txtName.Text;
                        if (txtCodeManual.Text.Trim() != string.Empty)
                        {
                            itemCategory.Code = txtCodeManual.Text;
                        }
                        else
                        {
                            itemCategory.Code = txtCode.Text;
                        }
                        itemCategory.Description = txtDescription.Text;
                        db.SaveChanges();
                    }
                    else if (rbSubCategory.Checked)
                    {
                        VisibleRootCategory();
                        itemCategory.CategoryId = (int)cmbRootCategory.SelectedValue;
                        itemCategory.Name       = txtName.Text;
                        if (txtCodeManual.Text.Trim() != string.Empty)
                        {
                            itemCategory.Code = txtCodeManual.Text;
                        }
                        else
                        {
                            itemCategory.Code = txtCode.Text;
                        }
                        itemCategory.Description = txtDescription.Text;
                        db.SaveChanges();
                    }
                    else
                    {
                        MessageBox.Show("Please Select Category!");
                    }

                    DialogResult dialogResult = MessageBox.Show("Are you sure want to update ?", "Information", MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        db.ItemCategories.Attach(itemCategory);
                        db.Entry(itemCategory).State = System.Data.Entity.EntityState.Modified;
                        int count = db.SaveChanges();
                        if (count > 0)
                        {
                            MessageBox.Show(" updated");
                        }
                        else
                        {
                            MessageBox.Show(" failed");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " \n" + " Find system error! ", MessageBoxIcon.Warning.ToString());
            }
            LoadDataGridView();
            ClearAllTextBox();
            SetFormNewMode();
            HideRootCategory();
        }
Exemplo n.º 20
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim() == string.Empty && txtCostPrice.Text.Trim() == string.Empty &&
                txtSalePrice.Text.Trim() == string.Empty && txtCode.Text.Trim() == string.Empty &&
                txtDescription.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Please fill text box !");
                return;
            }
            try
            {
                if (!_isUpdateMode)
                {
                    try
                    {
                        TextBoxValue();
                        db.Items.Add(item);
                        int count = db.SaveChanges();
                        if (count > 0)
                        {
                            MessageBox.Show("Successfully Item Saved");
                        }
                        else
                        {
                            MessageBox.Show("Failed Insertion");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "\n" + "Please fill text box!");
                    }
                }

                if (_isUpdateMode)
                {
                    DialogResult dialogResult = MessageBox.Show("Are you sure want to update ?", "Information", MessageBoxButtons.YesNo,
                                                                MessageBoxIcon.Information);
                    if (dialogResult == DialogResult.Yes)
                    {
                        TextBoxValue();
                        db.Items.Attach(item);
                        db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        int count = db.SaveChanges();

                        if (count > 0)
                        {
                            MessageBox.Show("item updated");
                        }
                        else
                        {
                            MessageBox.Show("item update failed");
                        }
                    }
                }
                ClearAllTextBox();
                LoadDataGridViewItem();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " \n" + " Find system error! ", MessageBoxIcon.Warning.ToString());
            }
        }