/// <summary> /// Get the model. /// </summary> /// <param name="ID"></param> /// <returns>Return model.</returns> public ClientFamily GetData(long ID) { ClientFamily clientFamily = new ClientFamily(); try { if (ID != 0) { DataSet data = new DataSet(); SqlParameter[] ObjParams = new SqlParameter[] { new SqlParameter("@ID", ID) }; data = new ADODataFunction().ExecuteDataset("dbo.Admin_GetClientFamilyDataFromID", ObjParams, CommandType.StoredProcedure); DataTable clientGroupTable = data.Tables[0]; if (clientGroupTable != null && clientGroupTable.Rows.Count > 0) { for (int i = 0; i < clientGroupTable.Rows.Count; i++) { clientFamily.Id = Convert.ToInt32(clientGroupTable.Rows[i]["ID"]); clientFamily.FamilyName = clientGroupTable.Rows[i]["FamilyName"].ToString(); clientFamily.FamilyShortName = clientGroupTable.Rows[i]["FamilyShortName"].ToString(); clientFamily.GroupID = Convert.ToInt32(clientGroupTable.Rows[i]["GroupID"]); clientFamily.AddressLine1 = clientGroupTable.Rows[i]["AddressLine1"].ToString(); clientFamily.AddressLine2 = clientGroupTable.Rows[i]["AddressLine2"].ToString(); clientFamily.CountryID = Convert.ToInt32(clientGroupTable.Rows[i]["CountryId"]); clientFamily.StateID = Convert.ToInt32(clientGroupTable.Rows[i]["StateId"]); clientFamily.CityID = Convert.ToInt32(clientGroupTable.Rows[i]["CityId"]); clientFamily.Pincode = Convert.ToInt32(clientGroupTable.Rows[i]["PinCode"]); clientFamily.Longitude = Convert.ToDecimal(clientGroupTable.Rows[i]["Longitude"]); clientFamily.Latitude = Convert.ToDecimal(clientGroupTable.Rows[i]["Latitude"]); clientFamily.IsActive = Convert.ToBoolean(clientGroupTable.Rows[i]["IsActive"]); clientFamily.CreatedOn = Convert.ToDateTime(clientGroupTable.Rows[i]["CreatedOn"]); } } return(clientFamily); } else { return(null); } } catch (Exception ex) { throw ex; } }
/// <summary> /// Add Update Data /// </summary> /// <param name="model"></param> /// <returns>Jsonresponse</returns> public JsonResponse AddUpdate(ClientFamily model) { JsonResponse resp = new JsonResponse(); try { // If these condition true the data was not exsits in the database if (!IsExsits(model.FamilyName)) { // 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 <ClientFamily>().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.FamilyName = model.FamilyName; models.FamilyShortName = model.FamilyShortName; models.GroupID = model.GroupID; models.AddressLine1 = model.AddressLine1; models.AddressLine2 = model.AddressLine2; models.CountryID = model.CountryID; models.StateID = model.StateID; models.CityID = model.CityID; models.IsActive = true; models.ModifiedOn = DateTime.Now; models.ModifiedBy = GetUserID(); _context.Set <ClientFamily>().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); }