Ejemplo n.º 1
0
        public IActionResult Create(replies reply)
        {
            if (HttpContext.Session.GetString("accId") != null)
            {
                try
                {
                    var result = db.replies.FirstOrDefault(item => item.Reply_id.Equals(reply.Reply_id));

                    if (result == null)
                    {
                        if (ModelState.IsValid)
                        {
                            db.replies.Add(reply);
                            db.SaveChanges();
                        }
                        else
                        {
                            ViewBag.Msg = "Model State is invalid!";
                        }
                    }
                    else
                    {
                        ViewBag.Msg = "This reply has already existed!";
                    }

                    return(View(@"~/Views/Web/replies/Create.cshtml"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
Ejemplo n.º 2
0
 public IActionResult Post([FromBody] Product product)
 {
     if (ModelState.IsValid)
     {
         if (product.id == 0)
         {
             _dbContext.Products.Add(product);
             _dbContext.SaveChanges();
             return(new ObjectResult(product));
         }
         else
         {
             var existingProduct = _dbContext.Products.FirstOrDefault(p => p.id == product.id);
             existingProduct.name      = product.name;
             existingProduct.type      = product.type;
             existingProduct.shortDesc = product.shortDesc;
             _dbContext.SaveChanges();
             return(new ObjectResult(existingProduct));
         }
     }
     else
     {
         return(new BadRequestObjectResult(ModelState));
     }
 }
Ejemplo n.º 3
0
        public IActionResult Create(connections connection)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin") || HttpContext.Session.GetString("accRole").Equals("Technician"))
            {
                try
                {
                    if (connection.Connection_image_thumbnail == null)
                    {
                        ViewBag.Msg = "You must select the connection's image!";
                    }
                    else if (ModelState.IsValid)
                    {
                        db.connections.Add(connection);
                        db.SaveChanges();

                        return(RedirectToAction("Index", "Connections"));
                    }
                    else
                    {
                        ViewBag.Msg = "Model State is invalid!";
                    }

                    return(View(@"~/Views/Admin/connections/Create.cshtml"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
Ejemplo n.º 4
0
        public IActionResult Create(replies replie)
        {
            var model = db.replies.FirstOrDefault(m => m.Reply_id.Equals(replie.Reply_id));

            if (model == null)
            {
                //if (ModelState.IsValid)
                //{


                db.replies.Add(replie);
                db.SaveChanges();
                ViewBag.msg = "The reply has been added";

                //}
                //else
                //{
                //    ViewBag.msg = "Failed to add item";

                //    }
            }
            else
            {
                ViewBag.msg = "Failed";
            }

            return(View(@"~/Views/Admin/feedbacks/Create.cshtml", model));
        }
        public IActionResult Create(tracks track, DateTime txtPeriod)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin") || HttpContext.Session.GetString("accRole").Equals("Accountant") || HttpContext.Session.GetString("accRole").Equals("Technician"))
            {
                try
                {
                    var temp     = txtPeriod.AddMonths(1);
                    var month    = txtPeriod.Month;
                    var year     = txtPeriod.Year;
                    var dateFrom = new DateTime(year, month, 1).ToString("MM/dd/yyyy");
                    var dateTo   = temp.AddDays(-(temp.Day)).ToString("MM/dd/yyyy");

                    var check   = db.plans_orders.FirstOrDefault(item => item.Plans_orders_id.Equals(track.Track_plans_orders_id));
                    var results = db.tracks.Where(item => item.Track_plans_orders_id.Equals(track.Track_plans_orders_id)).ToList();
                    var result  = results.FirstOrDefault(item => item.Track_date_from.Equals(dateFrom));

                    track.Track_id        = track.Track_plans_orders_id + "-" + txtPeriod.ToString("MM-yyyy");
                    track.Track_date_from = dateFrom;
                    track.Track_date_to   = dateTo;
                    track.Track_status    = "Pending";

                    if (check == null)
                    {
                        ViewBag.Msg = "Invalid Plans Orders ID!";

                        return(View(@"~/Views/Admin/tracks/Create.cshtml"));
                    }

                    if (result != null)
                    {
                        ViewBag.PlansOrdersId = track.Track_plans_orders_id;
                        ViewBag.Msg           = "This track period has already existed!";

                        return(View(@"~/Views/Admin/tracks/Create.cshtml"));
                    }

                    if (txtPeriod == DateTime.MinValue)
                    {
                        ViewBag.PlansOrdersId = track.Track_plans_orders_id;
                        ViewBag.Msg           = "You must choose a track period!";

                        return(View(@"~/Views/Admin/tracks/Create.cshtml"));
                    }

                    db.tracks.Add(track);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Tracks"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }

                return(View(@"~/Views/Admin/tracks/Create.cshtml"));
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
Ejemplo n.º 6
0
        public string Post([FromBody] User user)
        {
            _context.Add(user);
            _context.SaveChanges();
            string ret = "Posted: " + user.Username;

            return(ret);
        }
        public IActionResult Create(accounts account)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin"))
            {
                try
                {
                    var id    = db.accounts.FirstOrDefault(item => item.Account_id.Equals(account.Account_id));
                    var phone = db.accounts.FirstOrDefault(item => item.Account_phone.Equals(account.Account_phone));
                    var email = db.accounts.FirstOrDefault(item => item.Account_email.Equals(account.Account_email));

                    if (id == null && phone == null && email == null)
                    {
                        if (ModelState.IsValid)
                        {
                            var PasswordMd5 = Encryptor.GetMd5Hash(account.Account_password);
                            account.Account_password = PasswordMd5;

                            db.accounts.Add(account);
                            db.SaveChanges();

                            return(RedirectToAction("Index", "Accounts"));
                        }
                        else
                        {
                            ViewBag.Msg = "Model State is invalid!";
                        }
                    }

                    if (id != null)
                    {
                        ViewBag.Msg = "This account id has already existed!";
                    }

                    if (phone != null)
                    {
                        ViewBag.Msg = "This account phone has already existed!";
                    }

                    if (email != null && !email.Equals("*****@*****.**"))
                    {
                        ViewBag.Msg = "This account email has already existed!";
                    }

                    if (HttpContext.Session.GetString("accRole").Equals("Technician"))
                    {
                        return(View(@"~/Views/Admin/Orders.cshtml"));
                    }

                    return(View(@"~/Views/Admin/accounts/Create.cshtml"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
Ejemplo n.º 8
0
        public string ResetPassword(string token, string password)
        {
            var user = _context.Users.FirstOrDefault(x => x.Token == token);

            user.Password = Security.HashSensitiveData(password);
            _context.Update(user);
            _context.SaveChanges();
            return("changed");
        }
Ejemplo n.º 9
0
 public ActionResult Create(StudentViewModel studentObj)
 {
     if (ModelState.IsValid)
     {
         db.student.Add(studentObj.students);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(studentObj));
 }
Ejemplo n.º 10
0
 public ActionResult Edit([Bind(Include = "idPoduzeće,imePoduzeće,opisPoduzeće,kontaktTelefon,kontaktEmail,primarnaDjelatnostPoduzeće,gradPoduzeće,županijaPoduzeće,ulicaPoduzeće")] poduzeće poduzeće)
 {
     if (ModelState.IsValid)
     {
         db.Entry(poduzeće).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", new { idPoduzeća = User.Identity.GetUserId() }));
     }
     return(View(poduzeće));
 }
        public IActionResult Create(bills bill)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin") || HttpContext.Session.GetString("accRole").Equals("Accountant"))
            {
                try
                {
                    if (bill.Bill_order_id != null)
                    {
                        var order       = db.orders.Find(bill.Bill_order_id);
                        var orderStatus = order.Order_status;

                        if (!orderStatus.Equals("Complete"))
                        {
                            ViewBag.Msg = "You cannot invoice when the order is not completed";

                            return(View(@"~/Views/Admin/Bills/Create.cshtml"));
                        }
                        else
                        {
                            order.Order_status = "Billed";
                        }
                    }

                    if (bill.Bill_track_id != null)
                    {
                        var track       = db.tracks.Find(bill.Bill_track_id);
                        var trackStatus = track.Track_status;

                        if (!trackStatus.Equals("Complete"))
                        {
                            ViewBag.Msg = "You cannot invoice when the track is not completed";

                            return(View(@"~/Views/Admin/Bills/Create.cshtml"));
                        }
                        else
                        {
                            track.Track_status = "Billed";
                        }
                    }

                    bill.Bill_status = "Unpaid";

                    db.bills.Add(bill);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Bills"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
 public async Task <ActionResult <Access> > CheckAccessCode(int reqId, [FromBody] AccessCode code)
 {
     try
     {
         Access access = new Access()
         {
             UserId  = 0,
             Granted = false
         };
         Request request = null;
         if (code != null || reqId > 0)
         {
             //logic
             if (reqId > 0)
             {
                 request = _context.Request.Where(r => r.Id == reqId).FirstOrDefault <Request>();
                 if (request.isCompleted)
                 {
                     return(access);
                 }
                 User user = _context.User.Where(u => u.Id == (_context.Request.Where(r => r.Id == request.Id).FirstOrDefault <Request>().User.Id)).FirstOrDefault <User>();
                 access.UserId       = user.Id;
                 access.Granted      = true;
                 request.isCompleted = true;
                 request.Response    = "Activattion Successful";
                 _context.Request.Update(request);
             }
             else
             {
                 User user = _context.User.Where(u => u.Code.Equals(code.Code)).FirstOrDefault <User>();
                 if (user != null)
                 {
                     access.UserId  = user.Id;
                     access.Granted = true;
                     request        = new Request()
                     {
                         User        = user,
                         Type        = "Acitvation",
                         isCompleted = true,
                         Response    = "Activattion successful"
                     };
                     _context.Request.Add(request);
                 }
             }
             _context.SaveChanges();
             return(Ok(access));
         }
         else
         {
             return(BadRequest(access));
         }
     }
     catch (Exception e)
     {
         e.GetBaseException();
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 13
0
        public IActionResult Create(equipments equipment, IFormFile txtFileName)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin") || HttpContext.Session.GetString("accRole").Equals("Technician"))
            {
                try
                {
                    var result = db.equipments.FirstOrDefault(item => item.Equipment_id.Equals(equipment.Equipment_id));
                    var vendor = db.vendors.FirstOrDefault(item => item.Vendor_id == equipment.Equipment_vendor_id);

                    if (vendor == null)
                    {
                        ViewBag.Msg = "This vendor id does not exist!";

                        return(View(@"~/Views/Admin/equipments/Create.cshtml"));
                    }

                    if (txtFileName == null)
                    {
                        ViewBag.Msg = "You must select the product's image!";

                        return(View(@"~/Views/Admin/equipments/Create.cshtml"));
                    }

                    if (result != null)
                    {
                        ViewBag.Msg = "This equipment has already existed!";

                        return(View(@"~/Views/Admin/equipments/Create.cshtml"));
                    }

                    string     path   = Path.Combine("wwwroot/assets/img/products/", txtFileName.FileName);
                    FileStream stream = new FileStream(path, FileMode.Create);

                    txtFileName.CopyToAsync(stream);
                    equipment.Equipment_image_thumbnail = txtFileName.FileName;

                    db.equipments.Add(equipment);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Equipments"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }

                return(View(@"~/Views/Admin/equipments/Create.cshtml"));
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
Ejemplo n.º 14
0
        public IActionResult Create(retailShowrooms retailShowroom)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin"))
            {
                try
                {
                    var name    = db.retailShowrooms.FirstOrDefault(item => item.RetailShowroom_name.Equals(retailShowroom.RetailShowroom_name));
                    var address = db.retailShowrooms.FirstOrDefault(item => item.RetailShowroom_address.Equals(retailShowroom.RetailShowroom_address));
                    var city    = db.cities.FirstOrDefault(item => item.City_id == retailShowroom.RetailShowroom_city_id);

                    if (name == null && address == null && city != null)
                    {
                        if (ModelState.IsValid)
                        {
                            db.retailShowrooms.Add(retailShowroom);
                            db.SaveChanges();

                            return(RedirectToAction("Index", "retailShowrooms"));
                        }
                        else
                        {
                            ViewBag.Msg = "Model State is invalid!";
                        }
                    }

                    if (name != null)
                    {
                        ViewBag.Msg = "This retail showroom name has already existed!";
                    }

                    if (address != null)
                    {
                        ViewBag.Msg = "This retail showroom address has already existed!";
                    }

                    if (city == null)
                    {
                        ViewBag.Msg = "This city id does not exist!";
                    }

                    return(View(@"~/Views/Admin/retailShowrooms/Create.cshtml"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
Ejemplo n.º 15
0
        public ActionResult Edit([Bind(Include = "idKorisnik,imeKorisnik,prezimeKorisnik,kratkiOpisKorisnik,registracijskiEmailKorisnik,kontaktEmailKorisnik,kontaktTelefonKorisnik,gradKorisnik,županijaKorisnik,ulicaKorisnik,kontaktEmailIstiKaoRegistracijskiEmail,putanjaDoProfilneSlike")] korisnik korisnik)
        {
            if (ModelState.IsValid)
            {
                if (korisnik.kontaktEmailIstiKaoRegistracijskiEmail == true)
                {
                    korisnik.kontaktEmailKorisnik = korisnik.registracijskiEmailKorisnik;
                }

                db.Entry(korisnik).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Details", new { idKorisnika = User.Identity.GetUserId() }));
            }
            return(View(korisnik));
        }
Ejemplo n.º 16
0
        public ActionResult UpravljanjeSlikomProfila(UploadImagesModels uploadImagesModels)
        {
            string idKorisnika = User.Identity.GetUserId();

            if (uploadImagesModels.ImageFile[0] == null)
            {
                TempData["shortMessage"] = "Niste odabrali niti jednu sliku...";
                return(RedirectToAction("Profil", new { id = idKorisnika }));
            }
            else
            {
                Random rnd        = new Random();
                int    brojGreski = 0;

                foreach (HttpPostedFileBase file in uploadImagesModels.ImageFile)
                {
                    string extension           = Path.GetExtension(file.FileName);
                    System.Drawing.Image image = System.Drawing.Image.FromStream(file.InputStream, true, true);
                    int width  = image.Width;
                    int height = image.Height;
                    if ((extension == ".png" || extension == ".jpg" || extension == ".bmp" || extension == ".jpeg") && width >= 1080 && width <= 2160 && height >= 800 && height <= 1440)
                    {
                        //
                    }
                    else
                    {
                        brojGreski++;
                    }
                }

                if (brojGreski > 0)
                {
                    TempData["shortMessage"] = "Dopuštene su samo slike .png, .jpg ili .bmp formata i moraju biti minimalno 1080x800 te maksimalno 2160x1440 piksela...";
                    return(RedirectToAction("Profil", new { id = idKorisnika }));
                }
                else
                {
                    foreach (HttpPostedFileBase file in uploadImagesModels.ImageFile)
                    {
                        string folderPath = "~/Images/";
                        string fileName   = Path.GetFileNameWithoutExtension(file.FileName);
                        string extension  = Path.GetExtension(file.FileName);
                        fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                        korisnik korisnik     = db.korisnik.Find(User.Identity.GetUserId());
                        string   putanjaSlike = Server.MapPath(korisnik.putanjaDoProfilneSlike);
                        if (System.IO.File.Exists(putanjaSlike))
                        {
                            System.IO.File.Delete(putanjaSlike);
                        }
                        korisnik.putanjaDoProfilneSlike = folderPath + fileName;
                        fileName = Path.Combine(Server.MapPath("~/Images/"), fileName);
                        file.SaveAs(fileName);
                        db.SaveChanges();
                    }

                    TempData["shortMessage"] = "Slika uspješno uploadana...";
                    return(RedirectToAction("Profil", new { id = idKorisnika }));
                }
            }
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> AddUser([FromBody] User user)
        {
            if (ModelState.IsValid)
            {
                User dbUser = null; //assume user does not exist

                dbUser = _context.Users.FirstOrDefault(x => x.Username == user.Username);

                //if user aready exist return
                if (dbUser != null)
                {
                    return(new BadRequestObjectResult("User already exists"));
                }
                //get today's date and save it under user entry date
                user.EntryDate = DateTime.Now;
                //encrypt password
                user.Password = Security.HashSensitiveData(user.Password);
                //generate token
                string tokenString = BuildToken();
                user.Token = tokenString;
                //Save User
                await _context.AddAsync(user);

                _context.SaveChanges();

                new OkObjectResult("User saved successfully");
            }
            else
            {
                return(new BadRequestObjectResult("user cannot be null"));
            }
            return(Ok(user));
        }
        public IActionResult Update(plans_orders item)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin") || HttpContext.Session.GetString("accRole").Equals("Accountant") || HttpContext.Session.GetString("accRole").Equals("Technician"))
            {
                try
                {
                    var result = db.plans_orders.Find(item.Plans_orders_id);

                    if (ModelState.IsValid)
                    {
                        result.Plans_orders_status = item.Plans_orders_status;

                        db.SaveChanges();

                        return(RedirectToAction("Index", "PlansOrders"));
                    }
                    else
                    {
                        ViewBag.Msg = "Model State is invalid!";
                    }

                    return(View(@"~/Views/Admin/plans-orders/Update.cshtml", result));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
Ejemplo n.º 19
0
 public async Task <IActionResult> Post([FromBody] User user)
 {
     if (user == null)
     {
         return(BadRequest("Invalid user Id"));
     }
     else if (user.Id <= 0)
     {
         return(BadRequest("Invalid user Id"));
     }
     else
     {
         List <User> users = _context.Users.ToList();
         for (int i = 0; i < users.Count; i++)
         {
             User tmpUser = users.ElementAt(i);
             if (tmpUser.Username.Equals(user.Username) && tmpUser.Surname.Equals(user.Surname))
             {
                 return(BadRequest("User already exist"));
             }
         }
     }
     _context.Users.Add(user);
     _context.SaveChanges();
     return(new OkResult());
 }
Ejemplo n.º 20
0
        public IActionResult createOrder(Order o)
        {
            Product prod = _context.products.SingleOrDefault(p => p.id == o.product_id);

            if (o.quantity <= prod.quantity)
            {
                prod.quantity -= o.quantity;
                _context.orders.Add(o);
                _context.SaveChanges();
            }
            else
            {
                TempData["orderError"] = $"Oh no! There aren't enough {prod.name}(s) in stock!";
            }
            return(RedirectToAction("orders"));
        }
Ejemplo n.º 21
0
        private void buttonAddAttachment_Click(object sender, EventArgs e)
        {
            if (!ValidateMadeBy())
            {
                return;
            }

            var fileMsg = (_fileData != null ? string.Empty : "(файл не добавлен)");

            if (MessageBox.Show(string.Join(string.Empty, "Действительно добавить", fileMsg, "?"),
                                "Подтвердите действие", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                using (var db = new ModelsContext())
                {
                    var attachment = new Attachment
                    {
                        MadeBy    = double.Parse(textBoxMadeBy.Text),
                        PaymentId = _accounting.PaymentId
                    };

                    if (_fileData != null)
                    {
                        attachment.FileName = _fileName;
                        attachment.File     = _fileData;
                    }

                    db.Attachments.Add(attachment);
                    db.SaveChanges();

                    LoadAttachments(_accounting);
                }
            }
        }
Ejemplo n.º 22
0
        private void DeleteItemRows()
        {
            if (MessageBox.Show("Действительно удалить выделенные предметы?",
                                "Подтвердите действие", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            try
            {
                foreach (DataGridViewRow dataGridViewRow in dataGridViewItems.SelectedRows)
                {
                    var currentItemRepairId = dataGridViewRow.Cells[0].Value.ToString();

                    var repairItemId = int.Parse(currentItemRepairId);

                    using (var db = new ModelsContext())
                    {
                        var repairItem = db.RepairItems.First(x => x.Id == repairItemId);
                        db.RepairItems.Remove(repairItem);
                        db.SaveChanges();
                    }
                }
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            LoadRepairItems();
        }
Ejemplo n.º 23
0
        private void buttonEditMaster_Click(object sender, System.EventArgs e)
        {
            try
            {
                var currentMasterRepairId = dataGridViewMasters.CurrentRow.Cells[0].Value.ToString();

                var inputBox = new InputBox.InputBox("Количество дней работы", "Введите количество: ", dataGridViewMasters.CurrentRow.Cells[4].Value.ToString(), true);

                var valueInputBox = inputBox.ToString();
                if (string.IsNullOrEmpty(valueInputBox) || int.Parse(valueInputBox) == 0)
                {
                    buttonRemoveMaster_Click(sender, e);
                    return;
                }

                using (var db = new ModelsContext())
                {
                    var masterRepairId = int.Parse(currentMasterRepairId);
                    var dayOfWorks     = int.Parse(valueInputBox);

                    var repairMaster = db.RepairMasters.FirstOrDefault(x => x.Id == masterRepairId);
                    repairMaster.DaysOfWork = dayOfWorks;

                    db.SaveChanges();
                }

                LoadRepairMasters();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Выделите строку для редактирования предмета.");
            }
        }
Ejemplo n.º 24
0
        private void dataGridViewMasters_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            try
            {
                if (dataGridViewMasters.SelectedRows.Count > 1)
                {
                    DeleteMasterRows();
                    e.Cancel = true;
                    return;
                }

                var currentMasterRepairId = dataGridViewMasters.CurrentRow.Cells[0].Value.ToString();

                var repairMasterId = int.Parse(currentMasterRepairId);
                if (MessageBox.Show("Действительно удалить мастера?",
                                    "Подтвердите действие", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    e.Cancel = true;
                    return;
                }

                using (var db = new ModelsContext())
                {
                    var repairMaster = db.RepairMasters.First(x => x.Id == repairMasterId);
                    db.RepairMasters.Remove(repairMaster);
                    db.SaveChanges();

                    LoadRepairMasters();
                }
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Выделите строку для редактирования предмета.");
            }
        }
Ejemplo n.º 25
0
        private void buttonRemoveItem_Click(object sender, System.EventArgs e)
        {
            try
            {
                if (dataGridViewItems.SelectedRows.Count > 1)
                {
                    DeleteItemRows();
                    return;
                }

                var currentItemRepairId = dataGridViewItems.CurrentRow.Cells[0].Value.ToString();
                var repairItemId        = int.Parse(currentItemRepairId);
                if (MessageBox.Show("Действительно удалить предметы?",
                                    "Подтвердите действие", MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }

                using (var db = new ModelsContext())
                {
                    var repairItem = db.RepairItems.First(x => x.Id == repairItemId);
                    db.RepairItems.Remove(repairItem);
                    db.SaveChanges();
                }

                LoadRepairItems();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Выделите строку для редактирования предмета.");
            }
        }
Ejemplo n.º 26
0
        private void buttonEditItem_Click(object sender, System.EventArgs e)
        {
            try
            {
                var currentItemRepairId = dataGridViewItems.CurrentRow.Cells[0].Value.ToString();

                var inputBox = new InputBox.InputBox("Количество предметов", "Введите количество: ", dataGridViewItems.CurrentRow.Cells[5].Value.ToString(), true);

                var valueInputBox = inputBox.ToString();
                if (string.IsNullOrEmpty(valueInputBox) || int.Parse(valueInputBox) == 0)
                {
                    buttonRemoveItem_Click(sender, e);
                    return;
                }

                using (var db = new ModelsContext())
                {
                    var itemRepairId = int.Parse(currentItemRepairId);
                    var amountItem   = int.Parse(valueInputBox);

                    var repairItem = db.RepairItems.FirstOrDefault(x => x.Id == itemRepairId);
                    repairItem.AmountItem = amountItem;

                    db.SaveChanges();
                }

                LoadRepairItems();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("Выделите строку для редактирования предмета.");
            }
        }
Ejemplo n.º 27
0
        private void removeRepairToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            if (MessageBox.Show(
                    "Удалить ремонт?",
                    "Подтвердите действие", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                using (var db = new ModelsContext())
                {
                    var idRepair = _repair.Id;

                    var repirItem   = db.RepairItems.FirstOrDefault(x => x.RepairId == idRepair);
                    var repirMaster = db.RepairMasters.FirstOrDefault(x => x.RepairId == idRepair);
                    if (repirItem != null || repirMaster != null)
                    {
                        if (MessageBox.Show(
                                "Ремонт заполнен предметами и/или местерами. Все равно удалить?",
                                "Действительно удалить?", MessageBoxButtons.OKCancel) != DialogResult.OK)
                        {
                            return;
                        }
                    }

                    var currentRepair = db.Repairs.FirstOrDefault(x => x.Id == idRepair);
                    if (currentRepair != null)
                    {
                        db.Repairs.Remove(currentRepair);
                        db.SaveChanges();
                        Close();
                        return;
                    }

                    MessageBox.Show("Удаление невозможно в силу непредвиденных обстоятельств.");
                }
            }
        }
Ejemplo n.º 28
0
        public IActionResult Create(plans plan, IFormFile txtFileName)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin") || HttpContext.Session.GetString("accRole").Equals("Technician"))
            {
                try
                {
                    var connection = db.connections.FirstOrDefault(item => item.Connection_id == plan.Plan_connection_id);

                    if (connection == null)
                    {
                        ViewBag.Msg = "This connection id does not exist!";

                        return(View(@"~/Views/Admin/plans/Create.cshtml"));
                    }

                    if (txtFileName == null)
                    {
                        ViewBag.Msg = "You must select the product's image!";

                        return(View(@"~/Views/Admin/plans/Create.cshtml"));
                    }

                    plan.Plan_image_thumbnail = txtFileName.FileName;

                    if (ModelState.IsValid)
                    {
                        db.plans.Add(plan);
                        db.SaveChanges();

                        return(RedirectToAction("Index", "Plans"));
                    }
                    else
                    {
                        ViewBag.Msg = "Model State is invalid!";
                    }

                    return(View(@"~/Views/Admin/plans/Create.cshtml"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
        public IActionResult Create(vendors vendor)
        {
            if (HttpContext.Session.GetString("accRole").Equals("Admin"))
            {
                try
                {
                    var result  = db.vendors.FirstOrDefault(item => item.Vendor_id.Equals(vendor.Vendor_id));
                    var address = db.vendors.FirstOrDefault(item => item.Vendor_address.Equals(vendor.Vendor_address));

                    if (result == null)
                    {
                        if (address == null)
                        {
                            if (ModelState.IsValid)
                            {
                                db.vendors.Add(vendor);
                                db.SaveChanges();

                                return(RedirectToAction("Index", "Vendors"));
                            }
                            else
                            {
                                ViewBag.Msg = "Model State is invalid!";
                            }
                        }
                        else
                        {
                            ViewBag.Msg = "This vendor address has already existed!!";
                        }
                    }
                    else
                    {
                        ViewBag.Msg = "This vendor has already existed!";
                    }

                    return(View(@"~/Views/Admin/vendors/Create.cshtml"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Error: ", ex.Message);
                }
            }

            return(View(@"~/Views/Admin/ErrorPemission.cshtml"));
        }
        public JsonResult BookIssue(IssuedBooks issuedBooks)
        {
            var Book = db.book.FirstOrDefault(b => b.bookId == issuedBooks.bookId);

            if (issuedBooks != null && Book != null)
            {
                db.issuedBook.Add(issuedBooks);
                db.SaveChanges();
                Book.isAvailable = false;

                db.Entry(Book).State = EntityState.Modified;
                db.SaveChanges();
                return(Json(new { result = "success" }));
            }
            else
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }