예제 #1
0
        public Mobile GenerateToken(string imei, string idUsuario)
        {
            if (string.IsNullOrEmpty(imei))
            {
                throw new ArgumentNullException("O parâmetro imei passado está inválido.");
            }

            Mobile mobile = DbSet.FirstOrDefault(t => t.Imei == imei);

            if (mobile == null)
            {
                throw new Exception("MobileRepository.GenerateToken - Não foi encontrado o IMEI cadastrado na Base de dados.");
            }

            try
            {
                mobile.AuthToken = AESCrypt.Encrypt(idUsuario + ":" + Guid.NewGuid().ToString());
                mobile.IssuedOn  = DateTime.Now;
                mobile.ExpiresOn = DateTime.Now.AddMonths(1);

                //Criando o token
                DbSet.Attach(mobile);
                Context.Entry(mobile).State = EntityState.Modified;
                Context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception("MobileRepository.GenerateToken - Erro ao gerar o Token para o IMEI: " + imei, ex);
            }

            return(mobile);
        }
예제 #2
0
 public ActionResult Edit([Bind(Include = "OPSystemId,OpSystemName,Description")] OPSystem oPSystem)
 {
     if (ModelState.IsValid)
     {
         if (CanUpdateOPSystem(oPSystem))
         {
             db.Entry(oPSystem).State = EntityState.Modified;
             db.SaveChanges();
             TempData["OPSystemStatusMessage"] = "Operating system has been updated successfully!";
             return(RedirectToAction("Index"));
         }
         DisplayOPSystemExistsMessage(oPSystem);
     }
     return(View(oPSystem));
 }
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #4
0
        public IActionResult PutAccessoryDetail(int id, List <AccessoryItems> accessory)
        {
            try
            {
                for (var i = 0; i < accessory.ToArray().Length; i++)
                {
                    if (id != accessory[i].AccessoryItemsId)
                    {
                        _context.AccessoryItems.Add(accessory[i]);
                    }
                    else
                    {
                        _context.Entry(accessory[i]).State = EntityState.Modified;
                    }
                }
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AccessoryItemsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #5
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            if (phonesGrid.SelectedItem == null)
            {
                return;
            }
            Phone phone = phonesGrid.SelectedItem as Phone;

            PhoneWindow phoneWindow = new PhoneWindow(new Phone
            {
                Id       = phone.Id,
                Category = phone.Category,
                Price    = phone.Price,
                Title    = phone.Title
            });

            if (phoneWindow.ShowDialog() == true)
            {
                phone = db.Phones.Find(phoneWindow.PhoneModel.Id);
                if (phone != null)
                {
                    phone.Category        = phoneWindow.PhoneModel.Category;
                    phone.Title           = phoneWindow.PhoneModel.Title;
                    phone.Price           = phoneWindow.PhoneModel.Price;
                    db.Entry(phone).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
예제 #6
0
        // редактирование
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            // если ни одного объекта не выделено, выходим
            if (phonesGrid.SelectedItem == null)
            {
                return;
            }
            // получаем выделенный объект
            Phone phone = phonesGrid.SelectedItem as Phone;

            PhoneWindow phoneWindow = new PhoneWindow(new Phone
            {
                Id       = phone.Id,
                Category = phone.Category,
                Price    = phone.Price,
                Title    = phone.Title
            });

            if (phoneWindow.ShowDialog() == true)
            {
                // получаем измененный объект
                phone = db.Phones.Find(phoneWindow.Phone.Id);
                if (phone != null)
                {
                    phone.Category        = phoneWindow.Phone.Category;
                    phone.Title           = phoneWindow.Phone.Title;
                    phone.Price           = phoneWindow.Phone.Price;
                    db.Entry(phone).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
예제 #7
0
 public ActionResult Edit([Bind(Include = "Model,Price,CompanyId")] Mobiles mob)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mob).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", mob.CompanyId);
     return(View(mob));
 }
예제 #8
0
 public IActionResult Delete(int?id)
 {
     if (id != null)
     {
         Phone phone = new Phone {
             Id = id.Value
         };
         db.Entry(phone).State = EntityState.Deleted;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(NotFound());
 }
예제 #9
0
        public async Task <IActionResult> Delete(int?id)
        {
            if (id != null)
            {
                Mobile mobile = new Mobile {
                    Id = id.Value
                };
                db.Entry(mobile).State = EntityState.Deleted;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(NotFound());
        }
예제 #10
0
 public ActionResult Edit([Bind(Include = "BrandId,BrandName")] Brand brand)
 {
     if (ModelState.IsValid)
     {
         if (CanUpdateBrand(brand))
         {
             db.Entry(brand).State = EntityState.Modified;
             db.SaveChanges();
             TempData["BrandStatusMessage"] = "Brand has been updated successfully!";
             return(RedirectToAction("Index"));
         }
         DisplayBrandExistsMessage(brand);
     }
     return(View(brand));
 }
 public ActionResult Edit([Bind(Include = "MobileModelId,ModelName,BrandId,Price,RAM,StorageCapacity,OPSystemId")] MobileModel mobileModel)
 {
     if (ModelState.IsValid)
     {
         if (CanUpdateModel(mobileModel))
         {
             db.Entry(mobileModel).State = EntityState.Modified;
             db.SaveChanges();
             TempData["ModelStatusMessage"] = "Model has been updated successfully!";
             return(RedirectToAction("Index"));
         }
         DisplayModelExistsMessage(mobileModel);
     }
     ViewBag.BrandId    = new SelectList(db.Brands, "BrandId", "BrandName", mobileModel.BrandId);
     ViewBag.OPSystemId = new SelectList(db.OperatingSystems, "OPSystemId", "OpSystemName", mobileModel.OPSystemId);
     return(View(mobileModel));
 }
예제 #12
0
 public void Update(Order order)
 {
     db.Entry(order).State = EntityState.Modified;
 }
예제 #13
0
 public void Update(Phone book)
 {
     db.Entry(book).State = EntityState.Modified;
 }
예제 #14
0
 public void Update(Phone item)
 {
     db.Entry(item).State = EntityState.Modified;
 }
예제 #15
0
 public ActionResult Edit(Purchases purch)
 {
     db.Entry(purch).State = EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
예제 #16
0
 public void Update(Phone phone)
 {
     db.Entry(phone).State = EntityState.Modified;
 }
예제 #17
0
        //   List<Phone> phones;

        public ActionResult EditDbData(int?Id, string Model, string Producer, int?counttr = 3)
        {
            Phone ph = new Phone();

            ph.Id       = (int)Id;
            ph.Producer = Producer;
            ph.Model    = Model;

            if (Id != null)
            {
                db.Entry(ph).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            //  int current = db.C.Phones.Count();


            IEnumerable <Phone> phonesPerPages_durak = db.Phones.OrderBy
                                                           (x => x.Id).Skip(0).
                                                       Take(db.Phones.Count()).ToList();



            int kol_vo = 1;

            foreach (var durak in phonesPerPages_durak)
            {
                if (durak.Id == Id)
                {
                    break;
                }
                kol_vo++;
            }



            int pageSize = (int)counttr;

            int pagetr = (int)Math.Ceiling((decimal)db.Phones.Count() / pageSize);
            int p_tek  = (int)Math.Ceiling((decimal)kol_vo / pageSize);

            IEnumerable <Phone> phonesPerPages = db.Phones.OrderBy
                                                     (x => x.Id).Skip((p_tek - 1) * pageSize).
                                                 Take(pageSize).ToList();


            PageInfo pageInfo = new PageInfo
            {
                PageNumber = p_tek,
                PageSize   = pageSize,
                TotalItems = db.Phones.Count()
            };

            IndexViewModel ivm = new IndexViewModel
            {
                PageInfo = pageInfo,
                Phones   = phonesPerPages
            };

            return(View("~/Views/Home/Index.cshtml", ivm));
        }
예제 #18
0
 public void Update(Order item)
 {
     db.Entry(item).State = EntityState.Modified;
 }