Ejemplo n.º 1
0
        //[ValidateAntiForgeryToken]
        public ActionResult UpdateTimePeriodForSignal(TimePeriodForSignal TimePeriodForSignalInfoForUpdate)
        {
            try
            {
                TimePeriodForSignal TimePeriodForSignal_Check = db.TimePeriodForSignal.Where(s => s.TimePeriodForSignalID == TimePeriodForSignalInfoForUpdate.TimePeriodForSignalID).FirstOrDefault();

                if (TimePeriodForSignal_Check == null)
                {
                    //TempData["AlreadyInsert"] = "TimePeriodForSignal Already Added. Choose different TimePeriodForSignal. ";

                    return(Json(new { UpdateSuccess = false, AlreadyInsert = true }, JsonRequestBehavior.AllowGet));
                }

                TimePeriodForSignal TimePeriodForSignal_Check_IfDuplicateDataExist = db.TimePeriodForSignal.Where(s => s.TimePeriodForSignalID != TimePeriodForSignalInfoForUpdate.TimePeriodForSignalID && s.SignalSign == TimePeriodForSignalInfoForUpdate.SignalSign).FirstOrDefault();

                if (TimePeriodForSignal_Check_IfDuplicateDataExist != null)
                {
                    //TempData["AlreadyInsert"] = "TimePeriodForSignal Already Added. Choose different TimePeriodForSignal. ";

                    return(Json(new { UpdateSuccess = false, DuplicateSignExist = true }, JsonRequestBehavior.AllowGet));
                }

                var TimePeriodForSignal_db = db.TimePeriodForSignal.Where(s => s.TimePeriodForSignalID == TimePeriodForSignalInfoForUpdate.TimePeriodForSignalID);
                TimePeriodForSignalInfoForUpdate.CreatedBy   = TimePeriodForSignal_db.FirstOrDefault().CreatedBy;
                TimePeriodForSignalInfoForUpdate.CreatedDate = TimePeriodForSignal_db.FirstOrDefault().CreatedDate;
                TimePeriodForSignalInfoForUpdate.UpdateBy    = AppUtils.GetLoginEmployeeName();
                TimePeriodForSignalInfoForUpdate.UpdateDate  = AppUtils.GetDateTimeNow();

                db.Entry(TimePeriodForSignal_db.SingleOrDefault()).CurrentValues.SetValues(TimePeriodForSignalInfoForUpdate);
                db.SaveChanges();

                TempData["UpdateSucessOrFail"] = "Update Successfully.";
                var temp = TimePeriodForSignal_db.ToList();
                var TimePeriodForSignal_Return = TimePeriodForSignal_db.Select(s =>
                                                                               new
                {
                    TimePeriodForSignalID = s.TimePeriodForSignalID,
                    UpToHours             = s.UpToHours,
                    SignalSign            = s.SignalSign
                });
                var JSON = Json(new { UpdateSuccess = true, TimePeriodForSignalUpdateInformation = TimePeriodForSignal_Return }, JsonRequestBehavior.AllowGet);
                JSON.MaxJsonLength = int.MaxValue;
                return(JSON);
            }
            catch
            {
                TempData["UpdateSucessOrFail"] = "Update Fail.";
                return(Json(new { UpdateSuccess = false, TimePeriodForSignalUpdateInformation = "" }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 2
0
 public ActionResult DeleteTimePeriodForSignal(int TimePeriodForSignalID)
 {
     try
     {
         TimePeriodForSignal TimePeriodForSignal = db.TimePeriodForSignal.Find(TimePeriodForSignalID);
         db.TimePeriodForSignal.Remove(TimePeriodForSignal);
         db.SaveChanges();
         return(Json(new { DeleteStatus = true, TimePeriodForSignalID = TimePeriodForSignalID }, JsonRequestBehavior.AllowGet));
     }
     catch (Exception ex)
     {
         return(Json(new { DeleteStatus = false, TimePeriodForSignalID = TimePeriodForSignalID }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 3
0
        public ActionResult InsertTimePeriodForSignalFromPopUp(TimePeriodForSignal TimePeriodForSignal_Client)
        {
            TimePeriodForSignal TimePeriodForSignal_Check = db.TimePeriodForSignal.Where(s => s.SignalSign == TimePeriodForSignal_Client.SignalSign).FirstOrDefault();

            if (TimePeriodForSignal_Check != null)
            {
                TempData["AlreadyInsert"] = "Time Period For Signal Already Added. Choose different TimePeriodForSignal. ";

                return(Json(new { SuccessInsert = false, AlreadyInsert = true }, JsonRequestBehavior.AllowGet));
            }


            TimePeriodForSignal TimePeriodForSignal_Return = new TimePeriodForSignal();

            try
            {
                TimePeriodForSignal_Client.UpToHours   = TimePeriodForSignal_Client.UpToHours;
                TimePeriodForSignal_Client.SignalSign  = TimePeriodForSignal_Client.SignalSign;
                TimePeriodForSignal_Client.CreatedBy   = AppUtils.GetLoginEmployeeName();
                TimePeriodForSignal_Client.CreatedDate = AppUtils.GetDateTimeNow();

                TimePeriodForSignal_Return = db.TimePeriodForSignal.Add(TimePeriodForSignal_Client);
                db.SaveChanges();

                if (TimePeriodForSignal_Return.TimePeriodForSignalID > 0)
                {
                    //  TempData["SaveSucessOrFail"] = "Save Successfully.";
                    return(Json(new { SuccessInsert = true, TimePeriodForSignal = TimePeriodForSignal_Return }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //   TempData["SaveSucessOrFail"] = "Save Failed.";
                    return(Json(new { SuccessInsert = false }, JsonRequestBehavior.AllowGet));
                }
            }
            catch
            {
                return(Json(new { SuccessInsert = false }, JsonRequestBehavior.AllowGet));
            }
        }