Exemplo n.º 1
0
        public ActionResult _EditUnit(string fullName, string note, int branchId = 0, int id = 0)
        {
            // kiểm tra quyền thêm sửa
            var sys = CheckActiveMenu.ReturnActive(SystemMessageConst.TypeAction.Update);

            if (sys.IsSuccess == false)
            {
                return(Json(new { result = sys }, JsonRequestBehavior.AllowGet));
            }

            var      db = new quanlydonviBusiness();
            tbl_Unit serviceCustomer = new tbl_Unit();

            serviceCustomer.unit_name   = fullName;
            serviceCustomer.description = note;
            serviceCustomer.id_center   = branchId;
            serviceCustomer.id          = id;

            var result = db.EditUnit(serviceCustomer);

            CheckRuleAndSaveLog.ReturnCheckRuleAndSaveLog(DbLogType.Update.ToString(), result.IsSuccess, JsonConvert.SerializeObject(new { log = "CapNhatThongTinDVT", newtdata = serviceCustomer }, Newtonsoft.Json.Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            }));


            return(Json(new { result }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "id,name,shortCode,convertParameter")] tbl_Unit tbl_unit)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tbl_unit).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tbl_unit));
 }
Exemplo n.º 3
0
        public PartialViewResult Edit(string id)
        {
            tbl_Unit obj = (new UnitService()).GetUnitByID(id);

            if (obj == null)
            {
                obj = (new UnitService()).InitEmpty();
            }
            return(PartialView("EditUnit", obj));
        }
Exemplo n.º 4
0
        public SystemMessage AddUnit(tbl_Unit customer)
        {
            SystemMessage systemMessage = new SystemMessage();

            try
            {
                var check = ValidateCustomer(customer);
                if (check != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = check;
                    return(systemMessage);
                }

                var checkBranch = db.Branch.FirstOrDefault(ob => ob.Id == customer.id_center);
                if (checkBranch == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Đại lý không tồn tại !!!!";
                    return(systemMessage);
                }

                var checkSDT = db.tbl_Unit.FirstOrDefault(m => m.unit_name == customer.unit_name && m.id_center == customer.id_center);
                if (checkSDT != null && checkSDT.isactive == true)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Tên đơn vị đã tồn tại";
                    return(systemMessage);
                }
                else if (checkSDT != null && checkSDT.isactive == false)
                {
                    checkSDT.isactive    = true;
                    checkSDT.description = customer.description;

                    db.SaveChanges();
                    systemMessage.IsSuccess = true;
                    systemMessage.Message   = SystemMessageConst.systemmessage.AddSuccess;
                    return(systemMessage);
                }
                else
                {
                    db.tbl_Unit.Add(customer);
                    db.SaveChanges();
                    systemMessage.IsSuccess = true;
                    systemMessage.Message   = SystemMessageConst.systemmessage.AddSuccess;
                    return(systemMessage);
                }
            }
            catch (Exception e)
            {
                systemMessage.IsSuccess = false;
                systemMessage.Message   = e.ToString();
                return(systemMessage);
            }
        }
Exemplo n.º 5
0
        public SystemMessage EditUnit(tbl_Unit customer)
        {
            SystemMessage systemMessage = new SystemMessage();

            try
            {
                var check = ValidateCustomer(customer);
                if (check != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = check;
                    return(systemMessage);
                }

                var checkExisted = db.tbl_Unit.FirstOrDefault(ob => ob.id == customer.id && ob.id_center == customer.id_center);
                if (checkExisted == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = SystemMessageConst.systemmessage.NoData;
                    return(systemMessage);
                }
                var checkBranch = db.Branch.FirstOrDefault(ob => ob.Id == customer.id_center);
                if (checkBranch == null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Đại lý không tồn tại !!!!";
                    return(systemMessage);
                }

                var checkten = db.tbl_Unit.FirstOrDefault(m => m.unit_name == customer.unit_name && m.id != customer.id && m.id_center == customer.id_center && m.isactive == true);
                if (checkten != null)
                {
                    systemMessage.IsSuccess = false;
                    systemMessage.Message   = "Tên đơn vị đã tồn tại";
                    return(systemMessage);
                }

                checkExisted.unit_name   = customer.unit_name;
                checkExisted.description = customer.description;


                db.SaveChanges();
                systemMessage.IsSuccess = true;
                systemMessage.Message   = SystemMessageConst.systemmessage.EditSuccess;
                return(systemMessage);
            }
            catch (Exception e)
            {
                systemMessage.IsSuccess = false;
                systemMessage.Message   = e.ToString();
                return(systemMessage);
            }
        }
Exemplo n.º 6
0
        public string ValidateCustomer(tbl_Unit customer)
        {
            string rs  = null;
            var    vld = new ValidateUtils();

            rs = vld.CheckRequiredField(customer.unit_name, "Tên đơn vị", 1, 50);
            if (rs != null)
            {
                return(rs);
            }
            return(null);
        }
Exemplo n.º 7
0
        public tbl_Unit InitEmpty()
        {
            var obj = new tbl_Unit();

            obj.Id          = 0;
            obj.Name1       = "";
            obj.Name2       = "";
            obj.Description = "";
            obj.Status      = 1;
            obj.Value       = "1";
            return(obj);
        }
Exemplo n.º 8
0
        // GET: /Unit/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            tbl_Unit tbl_unit = db.tbl_Unit.Find(id);

            if (tbl_unit == null)
            {
                return(HttpNotFound());
            }
            return(View(tbl_unit));
        }
Exemplo n.º 9
0
        public ActionResult Create([Bind(Include = "id,name,shortCode,convertParameter")] tbl_Unit tbl_unit)
        {
            if (ModelState.IsValid)
            {
                db.tbl_Unit.Add(tbl_unit);
                ViewBag.message = "Unit Inserted Succesfully";
                db.SaveChanges();

                ModelState.Clear();
                return(View());
                //return RedirectToAction("Index");
            }

            return(View(tbl_unit));
        }
Exemplo n.º 10
0
        public JsonResult DeleteConfirmed(int id)
        {
            string success = string.Empty;
            // return Json(success, JsonRequestBehavior.AllowGet);
            tbl_Unit tbl_unit = db.tbl_Unit.Find(id);

            db.tbl_Unit.Remove(tbl_unit);
            int result = db.SaveChanges();

            if (result > 0)
            {
                success = "Data delete successfully";
            }
            //  return Json(success, JsonRequestBehavior.AllowGet);

            return(Json(new { result = success }));
        }
Exemplo n.º 11
0
        public int UpdateOrInsertUnit(tbl_Unit obj)
        {
            using (var db = _connectionData.OpenDbConnection())
            {
                if (obj.Id > 0)
                {
                    var query     = db.From <tbl_Unit>().Where(e => e.Id == obj.Id);
                    var objUpdate = db.Select(query).SingleOrDefault();
                    if (objUpdate != null)
                    {
                        //bjUpdate.Code = obj.Code;
                        objUpdate.Name1       = obj.Name1;
                        objUpdate.Status      = obj.Status;
                        objUpdate.Value       = obj.Value;
                        objUpdate.CreateDate  = DateTime.Now;
                        objUpdate.Createby    = comm.GetUserId();
                        objUpdate.Description = obj.Description;

                        return(db.Update(objUpdate));
                    }
                    return(-1);
                }
                else
                {
                    var queryCount = db.From <tbl_Unit>().Where(e => e.Name1 == obj.Name1 && e.SysHotelID == comm.GetHotelId()).Select(e => e.Id);
                    var objCount   = db.Count(queryCount);
                    if (objCount > 0)
                    {
                        return(comm.ERROR_EXIST);
                    }

                    obj.SysHotelID = comm.GetHotelId();
                    return((int)db.Insert(obj, selectIdentity: true));
                }
            }
        }
Exemplo n.º 12
0
        public ActionResult Update(tbl_Unit obj)
        {
            int result = new UnitService().UpdateOrInsertUnit(obj);

            return(Json(new { result = result }, JsonRequestBehavior.AllowGet));
        }