Ejemplo n.º 1
0
        private ActionResult ViewDetail(TblUnit ob, string msg, AlertMsgType?msgType)
        {
            try
            {
                if (ob == null)
                {
                    throw new Exception("ไม่พบข้อมูลที่ต้องการ, กรุณาลองใหม่อีกครั้ง");
                }

                if (!string.IsNullOrWhiteSpace(msg))
                {
                    WidgetAlertModel alert = new WidgetAlertModel()
                    {
                        Message = msg
                    };
                    if (msgType.HasValue)
                    {
                        alert.Type = msgType.Value;
                    }
                    ViewBag.Alert = alert;
                }
                return(View(ob));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", MVCController, new
                {
                    area = MVCArea,
                    msg = ex.GetMessage(),
                    msgType = AlertMsgType.Danger
                }));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Author: Phạm Huy Hùng
 /// Todo: cập nhật đối tượng
 /// </summary>
 /// <param name="o"></param>
 /// <returns></returns>
 public void Update(TblUnit o)
 {
     try
     {
         using (TkSchoolDbContext db = new TkSchoolDbContext())
         {
             var res = db.TblUnits.Where(x => x.UnitId == o.UnitId).Single();
             res.Name    = o.Name;
             res.Phone   = o.Phone;
             res.Fax     = o.Fax;
             res.Email   = o.Email;
             res.Status  = o.Status;
             res.Address = o.Address;
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException == null)
         {
             throw new Exception("TblUnitDao::Update" + ex.Message);
         }
         else
         {
             throw new Exception("TblUnitDao::Update" + ex.Message);
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Author: Phạm Huy Hùng
 /// Todo: tạo đối tượng mới
 /// </summary>
 /// <param name=""></param>
 /// <returns></returns>
 public void Create(TblUnit o)
 {
     try
     {
         using (TkSchoolDbContext db = new TkSchoolDbContext())
         {
             if (o != null)
             {
                 db.TblUnits.Add(o);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException == null)
         {
             throw new Exception("TblUnitDao::Create" + ex.Message);
         }
         else
         {
             throw new Exception("TblUnitDao::Create" + ex.Message);
         }
     }
 }
Ejemplo n.º 4
0
        public JsonResult TblUnitDelete(string id)
        {
            TblUnit o = new TblUnit();

            o.UnitId = id;
            new TblUnitDao().Delete(o);
            return(Json(JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> RegisterUnit([FromBody] TblUnit unit)
        {
            var result = await Task.Run(() =>
            {
                APIResponse apiResponse = null;
                if (unit == null)
                {
                    return(Ok(new APIResponse()
                    {
                        status = APIStatus.PASS.ToString(), response = "object can not be null"
                    }));
                }

                try
                {
                    var unitlist = new UnitHelpers().GetList(unit.UnitName);
                    if (unitlist.Count() > 0)
                    {
                        return(Ok(new APIResponse()
                        {
                            status = APIStatus.PASS.ToString(), response = $"unit Code {nameof(unitlist)} is already exists ,Please Use Different Code "
                        }));
                    }

                    var result = new UnitHelpers().Register(unit);
                    if (result != null)
                    {
                        apiResponse = new APIResponse()
                        {
                            status = APIStatus.PASS.ToString(), response = result
                        };
                    }
                    else
                    {
                        apiResponse = new APIResponse()
                        {
                            status = APIStatus.FAIL.ToString(), response = "Registration Failed."
                        };
                    }

                    return(Ok(apiResponse));
                }
                catch (Exception ex)
                {
                    return(Ok(new APIResponse()
                    {
                        status = APIStatus.FAIL.ToString(), response = ex.Message
                    }));
                }
            });

            return(result);
        }
Ejemplo n.º 6
0
        public JsonResult TblUnitCreate(string id, string name, string phone, string fax, string email, string address, bool?status = false)
        {
            TblUnit o = new TblUnit();

            o.UnitId  = id;
            o.Name    = name;
            o.Phone   = phone;
            o.Fax     = fax;
            o.Email   = email;
            o.Status  = status;
            o.Address = address;
            new TblUnitDao().Create(o);
            return(Json(JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 7
0
        public TblUnit Update(TblUnit units)
        {
            try
            {
                using Repository <TblUnit> repo = new Repository <TblUnit>();
                repo.TblUnit.Update(units);
                if (repo.SaveChanges() > 0)
                {
                    return(units);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 8
0
        public TblUnit Register(TblUnit unit)
        {
            try
            {
                using Repository <TblUnit> repo = new Repository <TblUnit>();
                repo.TblUnit.Add(unit);
                if (repo.SaveChanges() > 0)
                {
                    return(unit);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 9
0
        public ActionResult Delete()
        {
            try
            {
                int     id = Request.Form["UnitId"].ParseInt();
                TblUnit ob = uow.Modules.Unit.Get(id);
                if (ob == null)
                {
                    return(RedirectToAction("Index", MVCController, new { msg = "ไม่พบข้อมูลที่ต้องการ", msgType = AlertMsgType.Warning }));
                }

                uow.Modules.Unit.Delete(ob);
                uow.SaveChanges();
                return(RedirectToAction("Index", MVCController, new { msg = "ลบข้อมูลเรียบร้อยแล้ว", msgType = AlertMsgType.Success }));
            }
            catch (Exception ex)
            { return(RedirectToAction("Index", MVCController, new { msg = ex.GetMessage(), msgType = AlertMsgType.Danger })); }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Author: Phạm Huy Hùng
 /// Todo: tìm kiếm đối tượng theo khóa chính
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public TblUnit FindById(TblUnit obj)
 {
     try
     {
         using (TkSchoolDbContext db = new TkSchoolDbContext())
         {
             return(db.TblUnits.SingleOrDefault(x => x.UnitId == obj.UnitId));
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException == null)
         {
             throw new Exception("TblUnitDao::FindById" + ex.Message);
         }
         else
         {
             throw new Exception("TblUnitDao::FindById" + ex.Message);
         }
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Author: Phạm Huy Hùng
 /// Todo: xóa đối tượng
 /// </summary>
 /// <param name="o"></param>
 /// <returns></returns>
 public void Delete(TblUnit o)
 {
     try
     {
         using (TkSchoolDbContext db = new TkSchoolDbContext())
         {
             var res = db.TblUnits.Where(x => x.UnitId == o.UnitId).SingleOrDefault();
             db.TblUnits.Remove(res);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException == null)
         {
             throw new Exception("TblUnitDao::Delete" + ex.Message);
         }
         else
         {
             throw new Exception("TblUnitDao::Delete" + ex.Message);
         }
     }
 }
Ejemplo n.º 12
0
        public IActionResult UpdateUnit([FromBody] TblUnit unit)
        {
            if (unit == null)
            {
                return(Ok(new APIResponse {
                    status = APIStatus.FAIL.ToString(), response = $"{nameof(unit)} cannot be null"
                }));
            }

            try
            {
                var         rs = new UnitHelpers().Update(unit);
                APIResponse apiResponse;
                if (rs != null)
                {
                    apiResponse = new APIResponse()
                    {
                        status = APIStatus.PASS.ToString(), response = rs
                    };
                }
                else
                {
                    apiResponse = new APIResponse()
                    {
                        status = APIStatus.FAIL.ToString(), response = "Updation Failed."
                    };
                }
                return(Ok(apiResponse));
            }
            catch (Exception ex)
            {
                return(Ok(new APIResponse()
                {
                    status = APIStatus.FAIL.ToString(), response = ex.Message
                }));
            }
        }
Ejemplo n.º 13
0
        public ActionResult SetDetail()
        {
            int     id = Request.Form["CategoryId"].ParseInt();
            TblUnit ob = uow.Modules.Unit.Get(id);

            if (ob.UnitId <= 0)
            {
                ob.CreatedBy   = CurrentUID;
                ob.CreatedDate = CurrentDate;
            }
            ob.UnitName    = Request.Form["UnitName"];
            ob.UnitDetail  = Request.Form["UnitDetail"];
            ob.FlagActive  = Request.Form["FlagActive"].ParseBoolean();
            ob.UpdatedBy   = CurrentUID;
            ob.UpdatedDate = CurrentDate;
            try
            {
                //Validate model b4 save

                uow.Modules.Unit.Set(ob);
                uow.SaveChanges();

                return(RedirectToAction("Index", new
                {
                    area = MVCArea,
                    controller = MVCController,
                    msg = "บันทึกข้อมูลเรียบร้อยแล้ว",
                    msgType = AlertMsgType.Success
                }));
            }
            catch (Exception ex)
            {
                string msg = ex.GetMessage(true);
                return(ViewDetail(ob, msg, AlertMsgType.Danger));
            }
        }
Ejemplo n.º 14
0
        public ActionResult Detail(int?id, string msg, AlertMsgType?msgType)
        {
            TblUnit ob = uow.Modules.Unit.Get(id ?? 0);

            return(ViewDetail(ob, msg, msgType));
        }