示例#1
0
        public async Task <ActionResult <bool> > PutUser(int id, User user)
        {
            if (id != user.Id)
            {
                return(false);
            }

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

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

            return(true);
        }
示例#2
0
        public ActionResult SaveOrUpdate(User model)
        {
            if (ModelState.IsValid)
            {
                using (MyDBContext dc = new MyDBContext())
                {
                    if (model.Id > 0) //Update
                    {
                        var original = dc.User.Where(a => a.Id == model.Id && a.IsCurier == true && a.Role != "admin").Include(x => x.UserDetails).FirstOrDefault();
                        if (original != null)
                        {
                            model.IsCurier = true;
                            model.Role     = "user";
                            model.Password = PassCrypt.EnryptString(model.Password);
                            dc.Entry(original).CurrentValues.SetValues(model);
                            dc.Entry(original.UserDetails).CurrentValues.SetValues(model.UserDetails);
                        }
                    }
                    else //Save
                    {
                        model.IsCurier = true;
                        model.Role     = "user";
                        model.Id       = 0;
                        model.Password = PassCrypt.EnryptString(model.Password);
                        dc.User.Add(model);
                    }
                    dc.SaveChanges();
                }
            }

            return(View("Index"));
        }
示例#3
0
        private void WFProfilesBindingNavigatorSaveItem_Click_1(object sender, EventArgs e)
        {
            //  WFProfile oldProfile = (WFProfile)wFProfilesBindingSource.Current;

            //update the new
            wFProfilesBindingSource.EndEdit();
            WFProfile current = (WFProfile)wFProfilesBindingSource.Current;


            var tagName = current.Tag.ToLower().Trim();

            var duplicate = MyDB.WFProfiles.FirstOrDefault(p => p.Tag.ToLower() == tagName);

            if (duplicate != null)
            {
                //MessageBox.Show("Event Tag is already existing.","ERROR", MessageBoxButtons.OK, MessageBoxIcon.Stop);

                MyDB.Entry(current).State = System.Data.Entity.EntityState.Modified;
                //MyDB.WFProfiles.Attach(current);
                MyDB.SaveChanges();
            }
            else
            {
                //MyDB.WFProfiles.Add(current);//Attach(current);
                MyDB.Entry(current).State = System.Data.Entity.EntityState.Added;
                MyDB.SaveChanges();
            }

            ReloadProfiles();
        }
示例#4
0
        public async Task <IActionResult> PutDZguba_Elektronika(int id, DZguba_Elektronika dZguba_Elektronika)
        {
            dZguba_Elektronika.id = id;

            dZguba_Elektronika.UpdatedDate           = DateTime.Now;
            _context.Entry(dZguba_Elektronika).State = EntityState.Modified;

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

            return(NoContent());
        }
示例#5
0
 public ActionResult Edit([Bind(Include = "maSlide,viTri,trangThai,image")] Slider slider)
 {
     if (ModelState.IsValid)
     {
         db.Entry(slider).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(slider));
 }
示例#6
0
 public ActionResult Edit([Bind(Include = "maGiay,trangThai,maLoai,tenGiay,slug,giaBan,giaNhap,ngayTao,image,chiTiet")] Giay giay)
 {
     if (ModelState.IsValid)
     {
         db.Entry(giay).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.maLoai = new SelectList(db.LoaiGiays, "maLoai", "tenLoai", giay.maLoai);
     return(View(giay));
 }
示例#7
0
 public ActionResult Edit([Bind(Include = "maBV,id_NV,maCD,slug,noiDung,trangThai,ngayTao,ngayDang,image,tenCD")] BaiViet baiViet)
 {
     if (ModelState.IsValid)
     {
         db.Entry(baiViet).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.maCD  = new SelectList(db.ChuDeBVs, "maCD", "tenCD", baiViet.maCD);
     ViewBag.id_NV = new SelectList(db.User_NV, "id_NV", "soCMND", baiViet.id_NV);
     return(View(baiViet));
 }
示例#8
0
        public async Task <bool> Delete(int key)
        {
            var exist = await DBContext.Set <ShopBridgeItemModel>().FindAsync(key);

            if (exist != null)
            {
                exist.IsDeleted = true;
                DBContext.Entry(exist).CurrentValues.SetValues(exist);
                await DBContext.SaveChangesAsync();
            }
            return(true);
        }
示例#9
0
 public void updatePrestadorDeServicios(PrestadorDeServicios PDS)
 {
     using (MyDBContext context = new MyDBContext())
     {
         PrestadorDeServicios pres = context.PrestadoresDeServicios.Include("direccionPostal").Single(p => p.idPrestador == PDS.idPrestador);
         if (pres != null)
         {
             context.Entry(pres).CurrentValues.SetValues(PDS);
             context.Entry(pres.direccionPostal).CurrentValues.SetValues(PDS.direccionPostal);
             context.SaveChanges();
         }
     }
 }
示例#10
0
 public void updateCompra(Compra compra)
 {
     using (MyDBContext context = new MyDBContext())
     {
         Compra comp = context.Compras.Include("egreso").Single(p => p.idCompra == compra.idCompra);
         if (comp != null)
         {
             context.Entry(comp).CurrentValues.SetValues(compra);
             context.Entry(comp.egreso).CurrentValues.SetValues(compra.egreso);
             context.SaveChanges();
         }
     }
 }
示例#11
0
        public DataImportWindow(Instrument instrument)
        {
            InitializeComponent();

            //reload the instrument first to make sure we have up-to-date data
            //TODO rewrite to use client
            using (var context = new MyDBContext())
            {
                context.Instruments.Attach(instrument);
                context.Entry(instrument).Reload();
                _instrument = instrument;
            }

            Title += " - " + _instrument.Symbol;

            //fill frequency combo box
            var values = MyUtils.GetEnumValues <BarSize>();

            foreach (BarSize s in values)
            {
                FrequencyComboBox.Items.Add(s);
            }
            FrequencyComboBox.SelectedItem = BarSize.OneDay;

            MinDT.Value = new DateTime(1950, 1, 1);
            MaxDT.Value = DateTime.Now;
        }
示例#12
0
        public async Task <IActionResult> Put(int id, [FromBody] EXPMaster _EXPMaster)
        {
            if (id != _EXPMaster.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#13
0
 public ActionResult SaveOrUpdate(ClientPackage model)
 {
     if (model.ClientId == 0)
     {
         TempData["msg"] = "<script>alert('Campul Client este obligatoriu!');</script>";
         return(View(model));
     }
     else
     {
         if (ModelState.IsValid)
         {
             using (MyDBContext dc = new MyDBContext())
             {
                 if (model.Id > 0) //Update
                 {
                     var original = dc.ClientPackage.Where(a => a.Id == model.Id).FirstOrDefault();
                     if (original != null)
                     {
                         dc.Entry(original).CurrentValues.SetValues(model);
                     }
                 }
                 else //Save
                 {
                     dc.ClientPackage.Add(model);
                 }
                 dc.SaveChanges();
             }
         }
         return(View("Index"));
     }
 }
示例#14
0
        public async Task <IActionResult> PutPago([FromRoute] int id, [FromBody] Pago pago)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pago.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#15
0
        public async Task <IActionResult> PutTipsForEveryOne([FromRoute] Guid id, [FromBody] TipsForEveryOne tipsForEveryOne)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tipsForEveryOne.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#16
0
        public void TestEntityState()
        {
            using (var context = new MyDBContext())
            {
                //获取最后一条记录
                //由于EF不支持Last()查询,因此,先对其进行降序排列,然后取第一条记录
                var client = (from c in context.OrderClients
                              orderby c.ClientID descending
                              select c).FirstOrDefault();
                if (client != null)
                {
                    DbEntityEntry <OrderClient> clientEntry = context.Entry <OrderClient>(client);
                    Console.WriteLine("\n修改属性前:状态={0}", clientEntry.State);
                    Assert.IsTrue(clientEntry.State == EntityState.Unchanged);
                    OrderClientHelper.PrintEntityPropertyValue(clientEntry, "PostCode");
                    //把邮编当成数字,加1,作为修改后的新值进行测试
                    int newPostCode = Int32.Parse(client.PostCode) + 1;
                    client.PostCode = newPostCode.ToString();
                    context.ChangeTracker.DetectChanges();
                    Console.WriteLine("\n修改属性后:状态={0}", clientEntry.State);
                    Assert.IsTrue(clientEntry.State == EntityState.Modified);
                    OrderClientHelper.PrintEntityPropertyValue(clientEntry, "PostCode");

                    int result = context.SaveChanges();
                    Assert.IsTrue(result == 1);
                    Console.WriteLine("\n保存到数据库后:状态={0}", clientEntry.State);
                    OrderClientHelper.PrintEntityPropertyValue(clientEntry, "PostCode");
                }
            }
        }
示例#17
0
        public async Task <IActionResult> PutArticles([FromRoute] Guid id, [FromBody] ArticlesDTO articles)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != articles.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#18
0
        public async Task <IActionResult> PutMulta([FromRoute] int id, [FromBody] Contrato contrato)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != contrato.ID)
            {
                return(BadRequest());
            }

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

            try
            {
                await CrearOEditarMulta(contrato.multas);

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

            return(Ok(contrato));
        }
示例#19
0
        public async Task <Product> PutProduct(int id, ProductPostRequest product)
        {
            var productToBeUpdated = await _context.Products.Include(prod => prod.Category).FirstOrDefaultAsync(prod => prod.productId == id);

            if (productToBeUpdated is null)
            {
                return(null);
            }

            if (product.ImageFiles != null)
            {
                productToBeUpdated.Images = new List <Image>(); //reset to zero image
                foreach (IFormFile file in product.ImageFiles)
                {
                    productToBeUpdated.Images.Add(new Image {
                        productId = productToBeUpdated.productId, imageUrl = await _filesService.SaveFilePath(file)
                    });
                }
            }
            try
            {
                _context.Entry(productToBeUpdated).CurrentValues.SetValues(product);
                productToBeUpdated.updatedDate = DateTime.Now;
                productToBeUpdated.Category    = await _context.Categories.FindAsync(product.categoryId);

                await _context.SaveChangesAsync();

                return(productToBeUpdated);
            }
            catch (System.Exception e)
            {
                return(null);
            }
        }
示例#20
0
        public async Task <int> UpdateEmployeeByIdAsync(int id, Employee employee)
        {
            int result = 0;

            try
            {
                var update = new Employee {
                    Id = id
                };
                _db.Employees.Attach(update);
                _db.Entry(update).State = EntityState.Modified;
                update.FirstName        = employee.FirstName;
                update.LastName         = employee.LastName;
                update.Title            = employee.Title;
                await _db.SaveChangesAsync();

                result = 1;
            }
            catch (Exception ex)
            {
                _logger.LogError(string.Format("Error when update employee by id: {0}: {1}", ex.Message,
                                               ex.InnerException != null ? ex.InnerException.Message : string.Empty,
                                               ex.InnerException != null && ex.InnerException.InnerException != null
                              ? ex.InnerException.InnerException.Message
                              : string.Empty));
            }

            return(result);
        }
        public async Task <IActionResult> PutEmail(string id, Email email)
        {
            email.id = id;


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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutDNagroda(string id, DNagroda dNagroda)
        {
            dNagroda.id = id;


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

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

            return(NoContent());
        }
        // PUT odata/Suppliers(5)
        public IHttpActionResult Put([FromODataUri] int key, Supplier supplier)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (key != supplier.Id)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SupplierExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(supplier));
        }
 public string CreateExam([FromBody] Exam exam)
 {
     try
     {
         exam.CreateDate = DateTime.Now.ToString();
         exam.PostLink   = exam.Post.Link;
         var post = DB.Posts.Find(exam.Post.Link);
         if (post == null)
         {
             exam.Post.Content = GetContentOfPost(exam.Post.Link);
             DB.Posts.Add(exam.Post);
         }
         else
         {
             DB.Entry <Post>(post).State = EntityState.Detached;
         }
         DB.Exams.Add(exam);
         DB.SaveChanges();
         return("Operation successfull");
     }
     catch (Exception e)
     {
         return("An error occured");
     }
 }
        public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

            employee.Id = id;

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

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

            return(NoContent());
        }
示例#26
0
        public IActionResult PutDog(int id, [FromBody] Dog dog)
        {
            if (!ModelState.IsValid)
            {
                return(HttpBadRequest(ModelState));
            }

            if (id != dog.Id)
            {
                return(HttpBadRequest());
            }

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

            try
            {
                _context.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DogExists(id))
                {
                    return(HttpNotFound());
                }
                else
                {
                    throw;
                }
            }

            return(new HttpStatusCodeResult(StatusCodes.Status204NoContent));
        }
示例#27
0
        /// <summary>
        /// Updates the instrument with new values. Instrument must have an ID.
        /// </summary>
        public static void UpdateInstrument(Instrument instrument)
        {
            if (!instrument.ID.HasValue)
            {
                return;
            }

            using (var context = new MyDBContext())
            {
                try
                {
                    //find it
                    Instrument instrumentFromDB = context.Instruments.First(x => x.ID == instrument.ID);
                    //update it
                    context.Entry(instrumentFromDB).CurrentValues.SetValues(instrument); //perhaps update all the underlying collections as well?

                    //save it
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Logger _logger = LogManager.GetCurrentClassLogger();
                    _logger.Log(LogLevel.Error, "Update instrument error: " + ex.Message);
                }
            }
        }
示例#28
0
        public async Task <IActionResult> PutPosts(int id, Posts posts)
        {
            if (id != posts.PostId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutArticle(int id, Article article)
        {
            if (id != article.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        // PUT odata/TodoItems(5)
        public IHttpActionResult Put([FromODataUri] Guid key, TodoItem todoitem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (key != todoitem.Id)
            {
                return(BadRequest());
            }

            todoitem.InSync = true;

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoItemExists(key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(todoitem));
        }