예제 #1
0
 public ActionResult Create(Category category)
 {
     try
     {
         if (category.ID > 0)
         {
             Category existCategory = (from c in context.Category where c.ID == category.ID select c).FirstOrDefault();
             existCategory.Name                 = category.Name;
             existCategory.PhotoFileName        = category.PhotoFileName;
             context.Entry(existCategory).State = EntityState.Modified;
             context.SaveChanges();
             //UploadFile();
             return(Json(new { IsSuccess = true, data = "Category Update Successfully!" }));
         }
         else
         {
             context.Category.Add(category);
             context.SaveChanges();
             return(Json(new { IsSuccess = true, data = "Category Save Successfully!" }));
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #2
0
        public ActionResult deteleadv(int id)
        {
            DemoContext   _context = new DemoContext();
            Advertisement objadv   = new AdvertisementHandler().GetDetailAdvertisement(id);

            foreach (var child in objadv.Images.ToList())
            {
                String PATH = Request.MapPath("~/" + child.Url);
                if (System.IO.File.Exists(PATH))
                {
                    System.IO.File.Delete(PATH);
                }
                if (PATH != null)
                {
                    _context.Entry(child).State = System.Data.Entity.EntityState.Deleted;
                    _context.SaveChanges();
                }
            }

            _context.Entry(objadv).State = System.Data.Entity.EntityState.Deleted;
            // _context.Advertisements.Remove(objadv);
            _context.SaveChanges();

            return(RedirectToAction("index", "home1"));
        }
예제 #3
0
        public ActionResult AddProvince(FormCollection data)
        {
            //Adding Query String
            User currentUser = (User)Session[WebUtil.CURRENT_USER];

            if (currentUser == null)
            {
                return(RedirectToAction("Login", "User", new { returnurl = "Province/AddProvince" }));
            }
            if (currentUser.IsRole(WebUtil.ADMIN_ROLE))
            {
                Province province = new Province();
                province.Name    = data["provinceName"];
                province.Country = new Country {
                    ID = Convert.ToInt32(data["countriesList"])
                };
                _context.Entry(province.Country).State = System.Data.Entity.EntityState.Unchanged;
                _context.Provinces.Add(province);
                _context.SaveChanges();
                return(RedirectToAction("ShowProvince", "Province"));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }
예제 #4
0
        public ActionResult AddCity(FormCollection data)
        {
            //Adding Query String
            User currentUser = (User)Session[WebUtil.CURRENT_USER];

            if (currentUser == null)
            {
                return(RedirectToAction("Login", "User", new { returnurl = "City/AddCity" }));
            }
            if (currentUser.IsRole(WebUtil.ADMIN_ROLE))
            {
                City city = new City();
                city.Name     = data["cityName"];
                city.Province = new Province {
                    ID = Convert.ToInt32(data["ProvinceID"])
                };
                _context.Entry(city.Province).State = System.Data.Entity.EntityState.Unchanged;
                _context.Ciities.Add(city);
                _context.SaveChanges();
                return(RedirectToAction("ShowCities", "City"));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
        }
        static void Main(string[] args)
        {
            DemoContext context = new DemoContext();

            //context.Database.EnsureDeleted();


            context.Database.EnsureCreated();
            Blog blog = new Blog()
            {
                Url = "http"
            };

            context.Blogs.Add(blog);
            context.Entry(blog).Property("CreateTime").CurrentValue     = DateTime.Now;
            context.Entry(blog).Property("LastUpdateTime").CurrentValue = DateTime.Now;
            context.SaveChanges();

            var  bloag = context.Blogs.Find(1);
            Post post  = new Post()
            {
                Title = "test",
                Url   = "http",
                Blog  = bloag
            };

            context.SaveChanges();
            var b = context.Posts.Find(1);

            Console.WriteLine("Done");
            Console.ReadKey();
        }
예제 #6
0
 public void Add(User obj)
 {
     using (DemoContext _context = new DemoContext())
     {
         _context.Entry(obj.City).State = EntityState.Unchanged;
         _context.Entry(obj.Role).State = System.Data.Entity.EntityState.Unchanged;
         _context.Users.Add(obj);
         _context.SaveChanges();
     }
 }
예제 #7
0
 public void Delete(TEntity entityToDelete)
 {
     //Single esta entidad no esta traqueada por el contexto, sino
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         //La tacha y luego la borra
         dbSet.Attach(entityToDelete);
     }
     //Si esta tachada solo pasa a borrarla
     dbSet.Remove(entityToDelete);
 }
예제 #8
0
 public void Add(Advertisement add)
 {
     using (DemoContext con = new DemoContext()) {
         con.Entry(add.City).State        = EntityState.Unchanged;
         con.Entry(add.Type).State        = EntityState.Unchanged;
         con.Entry(add.Status).State      = EntityState.Unchanged;
         con.Entry(add.SubCategory).State = EntityState.Unchanged;
         con.Entry(add.User).State        = EntityState.Unchanged;
         con.Advertisements.Add(add);
         con.SaveChanges();
     }
 }
예제 #9
0
        public void Add(User add)
        {
            using (DemoContext con = new DemoContext())
            {
                con.Entry(add.Role).State    = EntityState.Unchanged;
                con.Entry(add.Address).State = EntityState.Unchanged;


                con.Users.Add(add);
                con.SaveChanges();
            }
        }
예제 #10
0
 public ActionResult Create(Category entity)
 {
     if (ModelState.IsValid)
     {
         db.Entry <Category>(entity).State = System.Data.Entity.EntityState.Added;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View(entity));
     }
 }
예제 #11
0
 public void Add(Advertisement obj)
 {
     using (DemoContext _context = new DemoContext())
     {
         _context.Entry(obj.City).State        = EntityState.Unchanged;
         _context.Entry(obj.Type).State        = EntityState.Unchanged;
         _context.Entry(obj.SubCatagory).State = EntityState.Unchanged;
         _context.Entry(obj.Status).State      = EntityState.Unchanged;
         _context.Entry(obj.User).State        = EntityState.Unchanged;
         _context.Advertisements.Add(obj);
         _context.SaveChanges();
     }
 }
예제 #12
0
        public T UnProxy <T>(T proxyObject) where T : class
        {
            var proxyCreationEnabled = _ctx.Configuration.ProxyCreationEnabled;

            try
            {
                _ctx.Configuration.ProxyCreationEnabled = false;
                T poco = _ctx.Entry(proxyObject).CurrentValues.ToObject() as T;
                return(poco);
            }
            finally
            {
                _ctx.Configuration.ProxyCreationEnabled = proxyCreationEnabled;
            }
        }
예제 #13
0
        public async Task <IActionResult> PutGoogleRoadIcon([FromRoute] int id, [FromBody] GoogleRoadIcon googleRoadIcon)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutCustomerDetailList(string id, CustomerDetailList customerDetailList)
        {
            if (id != customerDetailList.CustomerName)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #15
0
        public IHttpActionResult PutCustomer(int id, Customer customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #16
0
        public async Task <IActionResult> PutFatura([FromRoute] long id, [FromBody] Fatura fatura)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != fatura.FaturaId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #17
0
        public ActionResult ChangePass(ChangePasswordModel data, int id)
        {
            // mazak na kr strongly bind :D
            DemoContext _context = new DemoContext();
            User        objUser  = new UserHandler().getUserById(data.UserId);


            // wait idiot, keys galat hay tari , is ko run kr

            /*= new UserHandler().getUserById(id);*/
            string pa = objUser.Password;

            if (ModelState.IsValid)
            {
                if (pa.Equals(data.CurrentPass))
                {
                    objUser.Password = data.NewPass;
                    // repeat kr ley.
                    _context.Entry(objUser).State = System.Data.Entity.EntityState.Modified;
                    _context.SaveChanges();
                    TempData.Add("PasUpdateAlert", new AlertModel("your Password have been changed  Successfully..!", AlertType.Success));
                }
                else
                {
                    TempData.Add("PasUpdateAlert", new AlertModel("Please Confirm your Current Password!", AlertType.Warning));
                }
            }
            return(View());
        }
예제 #18
0
        public async Task <IActionResult> PutAsset(int id, Asset asset)
        {
            if (id != asset.Id)
            {
                return(BadRequest());
            }

            _context.Entry(asset).State = EntityState.Modified;
            List <Variant> variants = GetVariants(asset);

            asset.SetVariants(variants);

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

            return(NoContent());
        }
        public async Task <IActionResult> PutContact(int id, Contact contact)
        {
            if (id != contact.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #20
0
        public async Task <IActionResult> PutDependents(int id, Dependents dependents)
        {
            if (id != dependents.dependent_id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #21
0
        public async Task <IActionResult> PutPareja(int id, Pajera pareja)
        {
            if (id != pareja.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #22
0
        public async Task <IActionResult> PutTodoItem(long id, TodoItem todoItem)
        {
            if (id != todoItem.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutRegions(int id, Regions regions)
        {
            if (id != regions.region_id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
예제 #25
0
        public ActionResult rejectPostStatus(int id)
        {
            DemoContext   _context = new DemoContext();
            Advertisement objAvd   = _context.Advertisements.Include(x => x.City.Province.Country).Include(x => x.Images).Include(x => x.Status).Include(x => x.SubCatagory.Catagory).Include(x => x.Type).Include(x => x.User).Where(x => x.ID.Equals(id)).SingleOrDefault();

            objAvd.Status = new AdvertisementStatus {
                ID = 3
            };

            _context.Entry(objAvd.Status).State = System.Data.Entity.EntityState.Unchanged;
            _context.Entry(objAvd).State        = System.Data.Entity.EntityState.Modified;


            BuildEmailTemplate(objAvd.ID);
            _context.SaveChanges();
            return(RedirectToAction("PenddingPost", new { area = "AdminSide", Controller = "Home" }));
        }
예제 #26
0
        public ActionResult EditCatagory(Catagory obj)
        {
            DemoContext _context = new DemoContext();

            _context.Entry <Catagory>(obj).State = System.Data.Entity.EntityState.Modified;
            _context.SaveChanges();
            return(RedirectToAction("showAllCatagories", "Catagory"));
        }
예제 #27
0
 public void DeleteEmployee(Employee employee)
 {
     if (employee == null)
     {
         throw new ArgumentNullException(nameof(employee));
     }
     _db.Entry(employee).State = EntityState.Deleted;
 }
예제 #28
0
        static void Main(string[] args)
        {
            using var context = new DemoContext();
            //var vlubs = context.Clues
            //    .Include(x => x.League)
            //    .Include(x => x.Players)
            //        .ThenInclude(y => y.Resume)
            //    .Include(x=>x.Players)
            //        .ThenInclude(y=>y.GamePlayers)
            //            .ThenInclude(z=>z.Game)
            //    .ToList();
            var Clue = context.Clues
                       .Where(x => x.Id == 2).FirstOrDefault();

            context.Entry(Clue).Collection(x => x.Players).Load();
            context.Entry(Clue).Reference(x => x.League).Load();
            Console.WriteLine(Clue.Players?.Count ?? 0);
        }
예제 #29
0
        public ResponseModel UpdateCustomer(Customer model)
        {
            var targetModel = context.Customers.FirstOrDefault(c => c.Id == model.Id);

            if (model == null)
            {
                return(ResponseHelper.GetFailModel("更新失败,查不到这条记录"));
            }
            targetModel = ResponseHelper.ConvertCustomerModel(model, targetModel);
            context.Entry <Customer>(targetModel).State = EntityState.Modified;
            var res = context.SaveChanges();

            if (res == 0)
            {
                return(ResponseHelper.GetFailModel("更新失败"));
            }
            return(ResponseHelper.GetSuccessModel("更新成功"));
        }
예제 #30
0
        public void Delete(Human human)
        {
            using (var ctx = new DemoContext())
            {
                var attachedProduct = ctx.Entry(human);
                if (attachedProduct == null)
                {
                    ctx.Humans.Attach(human);
                }
                else
                {
                    ctx.Entry(human);
                }

                ctx.Humans.Remove(human);
                ctx.SaveChanges();
            }
        }