/// <summary>
 /// Add Update Data
 /// </summary>
 /// <param name="model"></param>
 /// <returns>Jsonresponse</returns>
 public JsonResponse AddUpdate(RTAs model)
 {
     try
     {
         //  If these condition true the data was not exsits in the database
         if (!IsExsits(model.Name, model.Id))
         {
             //  If model.ID == 0 the data goes to the Add part.
             if (model.Id == 0)
             {
                 model.IsActive  = true;
                 model.CreatedOn = DateTime.Now;
                 model.CreatedBy = GetUserID();
                 _context.Set <RTAs>().Add(model);
                 int i = _context.SaveChanges();
                 if (i != 0)
                 {
                     resp.Status  = Constants.ResponseStatus.Success;
                     resp.Message = Constants.Service.Data_insert_success;
                 }
                 else
                 {
                     resp.Message = Constants.Service.Data_insert_failed;
                 }
             }
             //  Else data goes to the Update part.
             else
             {
                 resp.Message = Constants.Service.Data_Update_failed;
                 var models = GetData(model.Id);
                 if (models != null)
                 {
                     models.Name       = model.Name;
                     models.Address    = model.Address;
                     models.IsActive   = true;
                     models.ModifiedOn = DateTime.Now;
                     models.ModifiedBy = GetUserID();
                     _context.Set <RTAs>().Update(models);
                     int i = _context.SaveChanges();
                     if (i != 0)
                     {
                         resp.Status  = Constants.ResponseStatus.Success;
                         resp.Message = Constants.Service.Data_Update_success;
                     }
                 }
             }
         }
         // The data was in the database so, It return the else part
         else
         {
             resp.Message = Constants.ControllerMessage.Data_Exsists;
         }
     }
     catch (Exception)
     {
         resp.Message = Constants.Service.Common_message;
     }
     return(resp);
 }
Exemple #2
0
        /// <summary>
        /// Get the Data based on ID and return to the model to update view.
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        // [TypeFilter(typeof(AuthorizeAction), Arguments = new object[] { "Write" })]
        public IActionResult Update(int ID)
        {
            RTAs model = _interface.GetData(ID);

            if (model != null)
            {
                return(View("Index", model));
            }
            else
            {
                resp.Message = Constants.Service.Common_message;
                return(Json(resp));
            }
        }