Example #1
0
        public Regency Add(Regency regency)
        {
            _context.RegencyItems.Add(regency);
            _context.SaveChanges();

            return(regency);
        }
Example #2
0
        public Regency Update(Regency regencyChanges)
        {
            _context.Entry(regencyChanges).State = EntityState.Modified;
            _context.SaveChanges();

            return(regencyChanges);
        }
Example #3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            Regency regency = await db.Regencies.FindAsync(id);

            db.Regencies.Remove(regency);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public bool Insert(RegencyVM regencyVM)
        {
            var push = new Regency(regencyVM);
            //ini nih foreign key
            var getProvince = applicationContext.Provinces.SingleOrDefault(x => x.IsDelete == false && x.Id == regencyVM.ProvinceId);

            push.Province = getProvince;
            applicationContext.Regencies.Add(push);
            var result = applicationContext.SaveChanges();

            return(result > 0);
        }
Example #5
0
        public Regency Delete(int id)
        {
            Regency regency = _context.RegencyItems.Find(id);

            if (regency != null)
            {
                _context.RegencyItems.Remove(regency);
                _context.SaveChanges();
            }

            return(regency);
        }
Example #6
0
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,ProvinceId,CreateDate,UpdateDate,DeleteDate,IsDelete")] Regency regency)
        {
            if (ModelState.IsValid)
            {
                db.Entry(regency).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.ProvinceId = new SelectList(db.Provinces, "Id", "Name", regency.ProvinceId);
            return(View(regency));
        }
Example #7
0
 public async Task <IActionResult> CreateRegency(RegencyNewModel model)
 {
     if (ModelState.IsValid)
     {
         var regency = new Regency {
             Name        = model.Name,
             Description = model.Description
         };
         await _regencyService.Add(regency);
     }
     return(RedirectToActionPermanent(nameof(Index)));
 }
Example #8
0
 public RegencyParam(Regency regency)
 {
     this.Id         = regency.Id;
     this.Name       = regency.Name;
     this.Districts  = regency.Districts;
     this.CreateDate = regency.CreateDate;
     this.UpdateDate = regency.UpdateDate;
     this.DeleteDate = regency.DeleteDate;
     this.IsDelete   = regency.IsDelete;
     this.CreateBy   = ""; //isi
     this.UpdateBy   = ""; //isi
     this.DeleteBy   = ""; //isi
 }
        public async Task <ActionResult> Create([Bind(Include = "Id,Province_Id,Name")] Regency regency)
        {
            if (ModelState.IsValid)
            {
                db.Regencies.Add(regency);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.Province_Id = new SelectList(db.Provinces, "Id", "Name", regency.Provinces_Id);
            return(View(regency));
        }
Example #10
0
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Regency regency = await db.Regencies.FindAsync(id);

            if (regency == null)
            {
                return(HttpNotFound());
            }
            return(View(regency));
        }
        public bool Delete(int?Id)
        {
            var     result  = 0;
            Regency regency = Get(Id);

            regency.IsDelete   = true;
            regency.DeleteDate = DateTimeOffset.Now.ToLocalTime();
            result             = myContext.SaveChanges();
            if (result > 0)
            {
                status = true;
            }
            return(status);
        }
Example #12
0
        // GET: Regencies/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Regency regency = await db.Regencies.FindAsync(id);

            if (regency == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProvinceId = new SelectList(db.Provinces, "Id", "Name", regency.ProvinceId);
            return(View(regency));
        }
Example #13
0
        public bool Update(int?Id, RegencyParam regencyParam)
        {
            var     result     = 0;
            Regency getRegency = Get(Id);

            getRegency.Name       = regencyParam.Name;
            getRegency.Provinces  = myContext.Provinces.Find(regencyParam.Provinces_Id);
            getRegency.UpdateDate = DateTimeOffset.Now.LocalDateTime;
            result = myContext.SaveChanges();

            if (result > 0)
            {
                status = true;
            }
            return(status);
        }
Example #14
0
        [Authorize(Roles = "QL,Regency,RegencyD")] //Delete
        public int DeleteConfirmed(string[] inputCheck)
        {
            //System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Chắc chắn không?", "Thông báo", System.Windows.Forms.MessageBoxButtons.YesNo);
            int rowFinish = 0;

            if (inputCheck == null)
            {
                return(rowFinish);
            }
            //if (dialogResult == System.Windows.Forms.DialogResult.Yes)
            //{
            foreach (var s in inputCheck)
            {
                try
                {
                    int     idMenu = Convert.ToInt32(DefineFuntion.Decrypt(s));
                    Regency obj    = db.Regencies.Find(idMenu);
                    //1-them, 2- sua, 3-xoa, 4- khac
                    shared.CreateHistory(new History()
                    {
                        Name    = "Xóa Chức Vụ",
                        Contens = JsonConvert.SerializeObject(obj, Formatting.Indented, new JsonSerializerSettings()
                        {
                            ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                        }),
                        ItemId = obj.RegencyId,
                        Type   = (int)DefineFuntion.TypeHistory.Career,
                    });
                    db.Regencies.Remove(obj);
                    db.SaveChanges();
                    rowFinish++;
                }
                catch (Exception)
                {
                    int     idMenu = Convert.ToInt32(DefineFuntion.Decrypt(s));
                    Regency obj    = db.Regencies.Find(idMenu);
                    obj.Status = 3;
                    db.SaveChanges();
                }
            }
            //}
            // else if (dialogResult == System.Windows.Forms.DialogResult.No)
            //{
            // return rowFinish;
            //}
            return(rowFinish);
        }
Example #15
0
        public bool Delete(int?Id)
        {
            var     result  = 0;
            Regency regency = Get(Id);

            regency.IsDelete   = true;
            regency.DeleteDate = DateTimeOffset.Now.LocalDateTime;
            result             = myContext.SaveChanges();
            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool Insert(RegencyVM regencyVM)
        {
            var push         = new Regency(regencyVM);
            var getProviceId = myContext.Provinces.Find(regencyVM.Province_Id);

            push.Province = getProviceId;
            myContext.Regencys.Add(push);
            var result = myContext.SaveChanges();

            if (result > 0)
            {
                status = true;
            }
            else
            {
                status = false;
            }
            return(status);
        }
Example #17
0
        public bool Insert(RegencyParam regencyParam)
        {
            var result  = 0;
            var regency = new Regency();

            regency.Name       = regencyParam.Name;
            regency.Provinces  = myContext.Provinces.Find(regencyParam.Provinces);
            regency.CreateDate = DateTimeOffset.Now.LocalDateTime;
            myContext.Regencies.Add(regency);
            result = myContext.SaveChanges();
            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #18
0
        public ActionResult Create(Regency rengency, string typeName)
        {
            var shared = new SharedFuntionController();
            int ms     = 0;

            try
            {
                if (ModelState.IsValid)
                {
                    db.Regencies.Add(rengency);
                    db.SaveChanges();
                    ms = 1;
                    //1-them, 2- sua, 3-xoa, 4- khac
                    shared.CreateHistory(new History()
                    {
                        Name    = "Thêm Chức Vụ",
                        Contens = "",
                        ItemId  = rengency.RegencyId,
                        Type    = (int)DefineFuntion.TypeHistory.Regency,
                    });
                }
            }
            catch (Exception)
            {
                ms = 2;
            }
            if (ms != 2)
            {
                if (typeName == "savenew" || typeName == "")
                {
                    return(RedirectToAction("Create", new { mess = ms }));
                }
                else
                {
                    return(RedirectToAction("Edit", new { id = DefineFuntion.Encrypt(rengency.RegencyId), mess = ms }));
                }
            }
            ViewBag.Status = new SelectList(DefineFuntion.ListStatus, "Value", "Text", rengency.Status);
            return(View());
        }
Example #19
0
        public ActionResult Edit(Regency regency, string codeSystem, string typeName)
        {
            regency.RegencyId = Convert.ToInt32(DefineFuntion.Decrypt(codeSystem));
            int ms = 0;
            var me = db.Regencies.Find(regency.RegencyId);

            try
            {
                me.Name   = regency.Name;
                me.Status = regency.Status;
                me.Note   = regency.Note;
                db.SaveChanges();
                ms = 3;//Nếu cập nhật thành công
                //1-them, 2- sua, 3-xoa, 4- khac
                shared.CreateHistory(new History()
                {
                    Name    = "Xóa Chức Vụ",
                    Contens = JsonConvert.SerializeObject(me, Formatting.Indented, new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                    }),
                    ItemId = me.RegencyId,
                    Type   = (int)DefineFuntion.TypeHistory.Regency,
                });
            }
            catch (Exception)
            {
                ms = 4;//Nếu cập nhật không thành công
            }
            if (typeName == "savenew" || typeName == "")
            {
                return(RedirectToAction("Create", new { mess = ms }));
            }
            else
            {
                return(RedirectToAction("Edit", new { id = codeSystem, mess = ms }));
            }
        }
Example #20
0
 public async Task Add(Regency regency)
 {
     _context.Add(regency);
     await _context.SaveChangesAsync();
 }
Example #21
0
        public Regency Get(int?Id)
        {
            Regency regency = myContext.Regencies.Where(x => x.Id == Id).SingleOrDefault();

            return(regency);
        }